name是input標(biāo)簽的屬性值,jQuery提供了attr() 方法用于設(shè)置/改變屬性值
成都創(chuàng)新互聯(lián)公司是一家專業(yè)的成都網(wǎng)站建設(shè)公司,我們專注網(wǎng)站設(shè)計制作、成都做網(wǎng)站、網(wǎng)絡(luò)營銷、企業(yè)網(wǎng)站建設(shè),外鏈,廣告投放為企業(yè)客戶提供一站式建站解決方案,能帶給客戶新的互聯(lián)網(wǎng)理念。從網(wǎng)站結(jié)構(gòu)的規(guī)劃UI設(shè)計到用戶體驗提高,創(chuàng)新互聯(lián)力求做到盡善盡美。
$("input:text").attr("name");
$("input:text").prop("name"); // 也可以使用prop()方法獲取屬性
示例代碼如下
創(chuàng)建Html元素
div class="box"
span點擊按鈕獲取文本框的name屬性值:/spanbr
div class="content"
input type="text" name="test" value="這個文本框的name屬性值為test"
/div
input type="button" class="btn" value="獲取文本框name值"
/div
設(shè)置css樣式
div.box{width:300px;height:250px;padding:10px 20px;margin:20px;border:4px dashed #ccc;}
div.boxspan{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"));
});
})
Js代碼
:
$("div[id]")
選擇所有含有id屬性的div元素
$("input[name='newsletter']")
選擇所有的name屬性等于'newsletter'的input元素
$("input[name!='newsletter']")
選擇所有的name屬性不等于'newsletter'的input元素
$("input[name^='news']")
選擇所有的name屬性以'news'開頭的input元素
$("input[name$='news']")
選擇所有的name屬性以'news'結(jié)尾的input元素
$("input[name*='man']")
選擇所有的name屬性包含'news'的input元素
$("input[id][name$='man']")
可以使用多個屬性進(jìn)行聯(lián)合選擇,該選擇器是得到所有的含有id屬性并且那么屬性以man結(jié)尾的元素
attr(name|properties|key,value|fn)
參數(shù)
nameStringV1.0
屬性名稱
properties MapV1.0
作為屬性的“名/值對”對象
key,value
String,ObjectV1.0
屬性名稱,屬性值
key,function(index, attr)
String,FunctionV1.1
1:屬性名稱。
2:返回屬性值的函數(shù),第一個參數(shù)為當(dāng)前元素的索引值,第二個參數(shù)為原先的屬性值。
參數(shù)name 描述:
返回文檔中所有圖像的src屬性值。
jQuery 代碼:
$("img").attr("src");
:name是input標(biāo)簽的屬性值,jQuery提供了attr()方法用于設(shè)置/改變屬性值$("input:text").attr("name");$("input:text").prop("name");//也可以使用
分享名稱:jquery獲取name屬性值,jq根據(jù)name獲取input值
標(biāo)題路徑:http://vcdvsql.cn/article22/dsdehjc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、企業(yè)網(wǎng)站制作、網(wǎng)站建設(shè)、品牌網(wǎng)站設(shè)計、品牌網(wǎng)站制作、網(wǎng)頁設(shè)計公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)