`

JQuery总结之表单操作(select , div , checkbox 操作)

阅读更多

 

// JavaScript Document 

//1.表单元素的获取

//获取所有input元素

$(":input")

 

//获取所有checkbox元素 

$(":checkbox") 

 

//获取id为age的元素

$("#age").val();

 

//获取name为age的元素

$("input[name='age']").val();

 

//获取name为age的select元素

$("select[name='age']"); 

 

//获取name为remark的textaret元素

$("textarea[name='remark']");

 

//获取checkbox是否选中.

$("input[name='commandType']").attr("checked") ; 

 

//循环获取checkbox选择的值

$("input[name='project.builtProduct']").each(function(i){

if($(this).attr("checked")){

product++;

}

});

 

 

//获取select选中的项目

$("select[name='project.solution'").find("option:selected").text()

 

//设置第一项选中

$("select[name=modelId]")[0].selectedIndex=0;

/******

*

* 查找子元素

*/

//1.在div中查找input,table元素

$("#divId").find("input")

$("#divId").children("table")

 

//2.查找某个元素的父元素并添加样式

$("#id").parent().addClass('inpCheckOn')


 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics