用jquery怎样获取input标签中name值

时间:2013.04.01 发布人:JasonFroze

用jquery怎样获取input标签中name值

已解决问题

谷歌JasonFroze用户在2013.04.01提交了关于“大众迈特威用jquery怎样获取input标签中name值”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-10-24T10:10:51。希望大家能够帮助她。

详细问题描述及疑问:期待您的答案,希望你能感受到,我最真诚的谢意 !

希望以下的回答,能够帮助你。

第1个回答

用户名:景六k**a52013140  

name是input标签的属性值,jQuery提供了attr()方法用于设置/改变属性值

$("input:text").att息系向常触矛季r("name")校酸绍学均侵和发;
$("input:text").prop("name");//也可以使用prop()方法获取属性

示例代码如下

创建h**tml元素

<divc来自lass="box">
<span>点击按钮获取文本框的name属性值:</span><br>
<d至推几统ivclass="cont问答ent">
<in胡措孩puttype="tex亚那破t"name="t企微est"val斤ue="这个文本框的name属性值为test">
</板div>
<inputty盟座鲁首负假章秋热少pe="button"class="btn"value="获取夜目文本框name值">
</div>

设置css样式

***.box{width:300px;height:250px;padding:10px20px;margin:20px;border:4pxdashed#ccc;}
***.box>span{源助上求乐石节把去color:#999;font-styl待光课史判找演国完e:italic;}
div.content{width:250px;height:100px;margin:10px0;padding:**x20px;b事景读order:2p试境命拉肉xsolid#ff6666;}
input[type='text']{width:200px;height伟活:30px;border:none;}
input[type='button']{width:120px;height:30px;margin:10px;border:2pxsolid#ebbcbe;}

写jquery代码

$(function(){
$("input:button").click(function(){
alert($("input:text").attr("name"));
});
})

察效果