How to get name with jquery

(*-*)浩
Release: 2019-05-29 10:35:47
Original
6116 people have browsed it

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()
Copy after login

Traverses based on the name value:

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

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
Copy after login

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

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

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!

Related labels:
css
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!