用jquery怎樣獲取input標簽中name值

4年前 (2020-12-29)閱讀984回復0
連曉亦
連曉亦
  • 管理員
  • 發(fā)消息
  • 注冊排名3726
  • 經(jīng)驗值65
  • 級別管理員
  • 主題13
  • 回復0
樓主
印刷廠(chǎng)直印加工●彩頁(yè)1000張只需要69元●名片5元每盒-更多產(chǎn)品印刷報價(jià)?聯(lián)系電話(huà):138-1621-1622(微信同號)

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)察效果

0
0
收藏0
回帖

用jquery怎樣獲取input標簽中name值 期待您的回復!

取消
載入表情清單……
載入顏色清單……
插入網(wǎng)絡(luò )圖片

取消確定

圖片上傳中
編輯器信息
提示信息