gba*_*de_ 3 html javascript css jquery
我在这里有点困难。我正在尝试将<a>标记设置为外部 URL。但是每次我这样做时,都会将包含 URL 的 index.html 的本地路径添加到链接中。我查看了我的 jQuery 代码,但似乎没有看到问题所在。我什至使用 console.log(url) 进行测试,它正确返回 URL。
$('.smoothscroll').on("click", function() {
if (nav.hasClass('mobile')) nav.fadeOut('fast');
})
$('.smoothscroll').on('click', function (e) {
e.preventDefault();
var target = this.hash,
$target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top
}, 800, 'swing', function () {
window.location.hash = target;
});
});
$('#login').on('click', function (e){
e.preventDefault();
var url = $(this).attr('href');
window.open(url, '_blank');
});Run Code Online (Sandbox Code Playgroud)
<ul id="nav" class="nav">
<li class="current"><a class="smoothscroll" href="#hero">Home.</a></li>
<!--<li><a class="smoothscroll" href="#portfolio">Works.</a></li>-->
<li><a class="smoothscroll" href="#about">About Us.</a></li>
<li><a class="smoothscroll" href="#portfolio">Features.</a></li>
<li><a class="smoothscroll" href="#contact">Create Account.</a></li>
<li><a class="login" id="login" href="google.com">Login.</a></li>
</ul>Run Code Online (Sandbox Code Playgroud)
每次在新选项卡中打开新 URL 时,这就是我得到的:file:///C:/PASSIS%20-%20Landing%20Page/google.com