jquery怎么获取name的值

 我来答
伪布将啊19
推荐于2017-12-15 · 超过38用户采纳过TA的回答
知道答主
回答量:60
采纳率:0%
帮助的人:17.5万
展开全部
name是input标签的属性值,jQuery提供了attr() 方法用于设置/改变属性值
$("input:text").attr("name");
$("input:text").prop("name"); // 也可以使用prop()方法获取属性

示例代码如下
创建Html元素
<div class="box">
<span>点击按钮获取文本框的name属性值:</span><br>
<div class="content">
<input type="text" name="test" value="这个文本框的name属性值为test">
</div>
<input type="button" class="btn" value="获取文本框name值">
</div>

设置css样式
div.box{width:300px;height:250px;padding:10px 20px;margin:20px;border:4px dashed #ccc;}
div.box>span{color:#999;font-style:italic;}
div.content{width:250px;height:100px;margin:10px 0;padding:5px 20px;border:2px solid #ff6666;}
input[type='text']{width:200px;height:30px;border:none;}
input[type='button']{width:120px;height:30px;margin:10px;border:2px solid #ebbcbe;}

编写jquery代码
$(function(){
$("input:button").click(function() {
alert($("input:text").attr("name"));
});
})
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式