Home  >  Article  >  Web Front-end  >  jQuery operation basic control method example analysis_jquery

jQuery operation basic control method example analysis_jquery

WBOY
WBOYOriginal
2016-05-16 15:22:38926browse

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

Copy code The code is as follows:
$(".className")...... //className represents It’s the style of the control

2. Get the control based on its ID

Copy code The code is as follows:
$("#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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn