jQuery 获取属性
获取属性的方法
jQuery attr() 方法用于获取属性值。
可以获取id class values等属性
$(selector).attr("value") $(selector).attr("id") $(selector).attr("class")
获取属性实例
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="./js/jquery-3.1.0.min.js"></script>//引入jQuery文档 <script> $(document).ready(function(){ $("button").click(function(){ alert("全淘宝最好的店铺: " + $("#test").attr("value"));//获取value属性 }); }); </script> </head> <body> <p>店铺名:<input type="text" id="test" value="桃之夭夭古风工作室"></p> <button>点点看</button> </body> </html>
相关推荐
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17