Home  >  Article  >  Web Front-end  >  How to get name with jquery

How to get name with jquery

(*-*)浩
(*-*)浩Original
2019-05-29 10:35:476182browse

jquery searches based on the name attribute

How to get name with jquery

$("div[id]") //选择所有含有id属性的div元素 
$("input[name='keleyicom']") //选择所有的name属性等于'keleyicom'的input元素 

$("input[name!='keleyicom']") //选择所有的name属性不等于'keleyicom'的input元素 

$("input[name^='keleyi']") //选择所有的name属性以'keleyi'开头的input元素 
$("input[name$='keleyi']") //选择所有的name属性以'keleyi'结尾的input元素 
$("input[name*='keleyi']") //选择所有的name属性包含'keleyi'的input元素 

$("input[id][name$='keleyi']") //可以使用多个属性进行联合选择,该选择器是得到所有的含有id属性并且那么属性以keleyi结尾的元素
根据name取值:  

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

Traverses based on the name value:

$("input[name='mobile']").each(  
    function(){  
   
    alert($(this).val());  
}  
)

Take out the input in the form:

<script type="text/javascript" language="JavaScript" charset="UTF-8">    
$(document).ready(function(){    
var a=$("form input");    
$.each(    
    a,    
function(name,object){    
alert(name+":"+$(object).val());    
}    
);    
});    
</script>   
//得到值(多个的情况):  
$("input[name='mobile']")[0].value  

$("input[name='mobile']").get(1).value

-----jquery add and delete styles--------

//给一个标签添加样式:  
$("#id").addClass("style");  
//删除一个标签的样式:  
$("#id").removeClass("style");  
//注:"#id"  id是对应标签的id,style是对应css样式的名称  
//获取单选标签选中获得的值
$("input[name='xxxx']:checked").val();

The above is the detailed content of How to get name with jquery. For more information, please follow other related articles on the PHP Chinese website!

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