jQuery 如何设置元素不可用? 下面本篇文章给大家介绍一下. 有一定的参考价值, 有需要的朋友可以参考一下, 希望对大家有所帮助.
使用 jQuery 设置元素不可用
我们可以用 jQuery 改变 html 元素的非 CSS 的属性. 比如, 你可以禁用按钮.
当你把按钮设置成禁用以后, 按钮会变灰并且不能点击.
jQuery 有一个. prop() 的方法, 可以让你来调整元素的属性.
以下代码显示如何禁用所有按钮:
$("button").prop("disabled", true);
示例: 让 target1 按钮禁用
- <script>
- $(document).ready(function() {
- $("#target1").CSS("color", "red");
- $("#target1").prop("disabled", true);
- });
- </script>
- <!-- Only change code above this line. -->
- <div class="container-fluid">
- <h3 class="text-primary text-center">
- jQuery Playground
- </h3>
- <div class="row">
- <div class="col-xs-6">
- <h4>
- #left-well
- </h4>
- <div class="well" id="left-well">
- <button class="btn btn-default target" id="target1">
- #target1
- </button>
- <button class="btn btn-default target" id="target2">
- #target2
- </button>
- <button class="btn btn-default target" id="target3">
- #target3
- </button>
- </div>
- </div>
- <div class="col-xs-6">
- <h4>
- #right-well
- </h4>
- <div class="well" id="right-well">
- <button class="btn btn-default target" id="target4">
- #target4
- </button>
- <button class="btn btn-default target" id="target5">
- #target5
- </button>
- <button class="btn btn-default target" id="target6">
- #target6
- </button>
- </div>
- </div>
- </div>
- </div>
效果图:
更多 web 前端 https://www.html.cn/ 知识, 请查阅 HTML 中文网 !!
来源: http://www.css88.com/qa/jquery/18745.html