Home > Article > Web Front-end > jQuery operation basic control method example analysis_jquery
The examples in this article describe how to operate basic controls with jQuery. Share it with everyone for your reference, the details are as follows:
1. Get the control according to its style class
2. Get the control based on its ID
3. Get the control based on its name
$("input[name='objName']")...... /*$("check[name='objName']")......*/ $("[name=objName]:checkbox")...... $("select[name='objName']")......
4. Traverse a group of controls
$(".className").each(function(){ $(this).attr("title","点击维护"); //$(this)拿到当前遍历的对象 }); for(var i=0; i<$(".className").length; i++) { $(".className:eq("+i+")").attr("title","点击维护"); }
5. CSS style of operation control
$("#objId").css("属性名"); //获取当前对象的CSS属性,如:$("#userName").css("color");返回userName的颜色 $("#objId").css("属性名","值"); //给当前控件设置CSS属性,如:$("#userName").css("color","#FFCCFF");将userName的颜色设置为#FFCCFF
6. Common properties of operation controls
$("input[name='age']").attr("属性名"); //获取控件的基本属性 $("input[name='age']").attr("属性名","值"); //设置控件的基本属性,如:$("#input[name='age']").attr("size","30");
I hope this article will be helpful to everyone in jQuery programming.