Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未定义的href属性值javascript_Javascript_Jquery_Undefined_Href - Fatal编程技术网

未定义的href属性值javascript

未定义的href属性值javascript,javascript,jquery,undefined,href,Javascript,Jquery,Undefined,Href,我想要href值,但这给了我未定义的值,为什么 var hy = $('.Player a.sc-player').attr('href'); console.log(hy); <div id="Container"> <header> <div id="Player"> <div class="Player"> <a href="https://soundcloud.com/rapzilla/an

我想要href值,但这给了我未定义的值,为什么

var hy = $('.Player a.sc-player').attr('href');

console.log(hy);

<div id="Container">
  <header>
    <div id="Player">
      <div class="Player">
        <a href="https://soundcloud.com/rapzilla/andy-mineo-stop-the-traffic" class="sc-player"></a>
        <p>hellow</p>
        <a href="" class="download_song">Download</a>
      </div>
    </div>
    <!--/Player-->
  </header>**strong text**

$document.readyfunction{

    alert($('.Player a.sc-player').attr('href'))
});

您不能在一个变量中组合这两个值。您可以包含jquery库吗?我运行了您的代码,它正在记录href值,而不是未定义的值。使用$function{var hy=$'。Player a.sc-Player.attr'href';};使用jQuerydocument.ready中的代码