用jquery怎樣獲取input標簽中name值
name是input標簽的屬性值,jQuery提供了attr() 方法用于設置/改變屬性值
$("input:text").attr("name");
$("input:text").prop("name");??//?也可以使用prop()方法獲取屬性示例代碼如下
創(chuàng )建Html元素
;div?class="box";
;span;點(diǎn)擊按鈕獲取文本框的name屬性值:;/span;;br;
;div?class="content";
;input?type="text"?name="test"?value="這個(gè)文本框的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;}編寫(xiě)jquery代碼
$(function(){
$("input:button").click(function()?{
alert($("input:text").attr("name"));
})觀(guān)察效果