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 ?获取标签属性值的问题
原文地址:https://www.cnblogs.com/agansj/p/8583643.html