window.location = link.href;不工作

时间:2013-10-16 07:41:00

标签: window.location

<script type="text/javascript">
$(function() {
$("#btn_AddToBasket").click( function(e) { 
e.preventDefault();
$('#main_container').css("display","block"); 
$('#alert_box').css("display","block");
});

$("#mbback").click( function() { 
$('#main_container').css("display","none"); 
$('#alert_box').css("display","none");
});

});
$("#mbgo").click( function() { 
window.location = link.href;
});
</script>
<div id="main_container" style="display:none;">
  <div id="alert_box" style="display:none;">
    <div class="alert_box_inner">
      <div id="message_container"><img src="-/resources/E5/160997/Image/logo.png" />
        <div id="message_title">You must be 18+</div>
        <div id="message_text">Please be aware that in order to purchase this product you must confirm that you are 18 years old or older. By clicking yes, you legally acknowledge that you are 18 years old or older</div>
        <div id="message_bottons"><a id="mbback" href="#">Go back</a><a id="mbgo" href="#">Yes, I&#39;m over 18</a></div>
      </div>
    </div>
  </div>
</div>

我正在页面上进行年龄验证。单击#mbgo时,页面必须打开一个页面。但它没有开放。它必须打开#btn_AddToBasket的链接

1 个答案:

答案 0 :(得分:0)

问题在于功能

$("#mbgo").click( function() { 
    window.location = link.href;
});

变量link未定义,因此您的代码应该是     window.location = $("#btn_AddToBasket").attr("href");