jQuery-Selectors(选择器)的使用(九、表单对象属性篇)

系列文章导航:

jQuery-Selectors(选择器)的使用(一、基本篇)

jQuery-Selectors(选择器)的使用(二、层次篇)

jQuery-Selectors(选择器)的使用(三、简单篇)

jQuery-Selectors(选择器)的使用(四–五、内容篇&可见性篇)

jQuery-Selectors(选择器)的使用(六、属性篇)

jQuery-Selectors(选择器)的使用(七、子元素篇)

jQuery-Selectors(选择器)的使用(八、表单篇)

jQuery-Selectors(选择器)的使用(九、表单对象属性篇)


1. :enabled用法

定   义:匹配所有可用元素

返回值:Array

实   例:将ID为”div_a1″的DIV中所有可用的input元素的背景色改为红色


代   码: $(“#div_a1 input:enabled”).css(“background-color”,”red”); //点击按钮一将执行这句代码 DIV ID=”div_a1″


span ID=”span_a1″


texteara select

2. :disabled用法


定   义:匹配所有不可用元素

返回值:Array

实   例:将ID为”div_b1″的DIV中所有不可用的input元素的背景色改为红色


代   码: $(“#div_b1 input:disabled”).css(“background-color”,”red”); //点击按钮二将执行这句代码 DIV ID=”div_b1″


span ID=”span_b1″


texteara select

3. :checked用法


定   义:匹配所有选中的被选中元素(复选框、单选框等,不包括select中的option)

返回值:Array

实   例:将ID为”div_c1″的DIV中所有包含选中状态复选框的元素背景色改为红色


代   码: $(“#div_c1 :has(input[type=’checkbox’]:checked)”).css(“background-color”,”red”); //点击按钮三将执行这句代码 DIV ID=”div_c1″


span ID=”span_c1″ DIV id=”div_c1_1″ DIV id=”div_c1_2″

DIV id=”div_c1_3″ DIV id=”div_c1_4″
注意::has(selector)用法参见内容篇&可见性篇第3点, [type=’checkbox’]用法参见属性篇第2点。


4. :selected用法
定   义:匹配所有选中的option元素
返回值:Array
实   例:将ID为”div_d1″的DIV中所有select元素中选中的option元素的text值写入div_d1_1中
代   码: var SelectedText=$(“#div_d1 :selected”); //点击按钮四将执行这句代码

详细代码如下:
<
script type
=

text/javascript

>

   $(


#btn_4

).click(
function
(){
        

var
 SelectedText
=
$(

#div_d1 :selected

);
        

for
 (
var
 i
=
0
;i
<
SelectedText.length;i
++
)
        {
             $(


#div_d1_1

).append((i
+
1

+
 



+
SelectedText[i].text
+

 

);
        }
   });

<
/
script>

 

DIV ID=”div_d1″


span ID=”span_d1″ span option1 span option2 span option3 div select1 div C# div VB div jQuery  div select2 div Apple div Inter div Google  div select3 div U.S.A. div U.K. div China

DIV id=”div_d1_1″
注意:append(content)指向某元素内部追加content,在以后的章节中会有讲解,敬请关注。

 

   你可以下载这篇文章的HTML源文件:download

千百度
© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容