jQuery 獲取標簽屬性值的問題
阿新 • • 發佈:2018-03-16
reply pos att 就是 doc tle 分享 pic -i
css裏明明已經設置過了:
可還是獲取不了:
求指導。
jquery attr()無法獲取屬性值問題
css裏明明已經設置過了:
可還是獲取不了:
求指導。
-
一定是undefined,attr是用來獲得或設置標簽屬性的,不是用來獲得CSS屬性的。如果你有id是nn1的標簽,可以用ww=$("#nn1").css("top");來獲得CSS屬性。
-
標簽屬性和css屬性怎麽區別
追答<script type="text/javascript">
$(document).ready(function(){
alert($("#nn1").attr("title")); //在div標簽中的title就是標簽屬性,id也是標簽屬性,也就是出現在標簽裏的屬性;
alert($("#nn1").css("top")); //CSS屬性是在樣式表中的屬性;
});
</script>
<style type="text/css">
#nn1{
position:relative;
top:30px;
}
</style>
<div id="nn1" title="this is a div">abc</div>
jQuery 獲取標簽屬性值的問題