jquery 元素不可用怎么设置


本文摘自PHP中文网,作者藏色散人,侵删。

jquery元素不可用的设置方法:首先创建一个js示例文件;然后用jQuery改变HTML元素的非CSS的属性;最后通过“$("button").prop("disabled", true);”禁用所有按钮即可。

本教程操作环境:windows7系统、jquery1.10.0版本、thinkpad t480电脑。

推荐:《jquery视频教程》

使用jQuery设置元素不可用

我们可以用jQuery改变HTML元素的非CSS的属性。比如,你可以禁用按钮。

当你把按钮设置成禁用以后,按钮会变灰并且不能点击。

jQuery有一个.prop()的方法,可以让你来调整元素的属性。

以下代码显示如何禁用所有按钮:

1

$("button").prop("disabled", true);

示例:让target1按钮禁用

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

<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>

效果图:

1.gif

以上就是jquery 元素不可用怎么设置的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

介绍js的四种类型检测方法及根据jQuery写的工具方法

jQuery中w2ui是什么?

通过jQuery怎么移除点击事件

jQuery 2.x和1.x的区别是什么

jQuery怎么判断是否有某个属性

jQuery冲突问题怎么解决

jq怎么设置css样式

jQuery的语法结构有哪些

jQuery怎么比较两个数字大小

jQuery读取json乱码怎么办

更多相关阅读请进入《jQuery》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    暂无评论...