jquery和attr,unfind

lol*_*ola 1 jquery attributes


我的代码有什么问题?为什么.atrr()显示空?
谢谢

$(document).ready(function(){
   $('#push').click(function(){
      alert($('#push2').attr('href').val);
   }); 
});  
Run Code Online (Sandbox Code Playgroud)

HTML:

<div id="push">PUSH</div>
<a id="push2" href="http://www.google.com">PUSH Google</a>
Run Code Online (Sandbox Code Playgroud)

Nic*_*ver 8

.attr() 已经返回一个字符串,所以直接使用它(没有.val):

$(document).ready(function(){
    $('#push').click(function(){
        alert($('#push2').attr('href'));
    }); 
}); 
Run Code Online (Sandbox Code Playgroud)

你可以在这里测试一下.你undefined目前看到的原因是因为字符串对象的.val属性 :) undefined