浏览器将指定 href 的超链接解释为完全不同的 url
Browser interprets hyperlink specified href as a totally different url
我在 HTML 前端页面遇到奇怪的行为。
在该页面中:
https://www.cindycottage.com/novita/nastro-jolis-boutons.html
放置在边栏中的滑块中的按钮有一个奇怪的行为。
在HTML代码中指定了一个属性
onclick="window.location='some link'"
但浏览器指向另一个 url。将鼠标悬停在按钮上会在状态栏中显示错误的 url。我通过浏览器检查器验证没有 javascript 动态地改变 url。
按钮放置在表单内。因此,当您单击它时,您将转到 form
标记的 action
属性中指定的 url
。
您可以像这样使用 jQuery 来做到这一点:
$('#id_of_the_button').click(function(e) {
e.preventDefault();
window.location = 'Some url';
});
将 id_of_the_button
和 Some url
替换为所需的值。
尝试在 link 'return false;' 的 onclick 属性上附加
示例:
onclick="window.location='https://www.cindycottage.com/promozioni';return false;"
问题是按钮元素还绑定了提交事件,当您单击它时会调用该事件。 Return 错误;覆盖此默认行为;
我在 HTML 前端页面遇到奇怪的行为。
在该页面中: https://www.cindycottage.com/novita/nastro-jolis-boutons.html 放置在边栏中的滑块中的按钮有一个奇怪的行为。
在HTML代码中指定了一个属性 onclick="window.location='some link'" 但浏览器指向另一个 url。将鼠标悬停在按钮上会在状态栏中显示错误的 url。我通过浏览器检查器验证没有 javascript 动态地改变 url。
按钮放置在表单内。因此,当您单击它时,您将转到 form
标记的 action
属性中指定的 url
。
您可以像这样使用 jQuery 来做到这一点:
$('#id_of_the_button').click(function(e) {
e.preventDefault();
window.location = 'Some url';
});
将 id_of_the_button
和 Some url
替换为所需的值。
尝试在 link 'return false;' 的 onclick 属性上附加 示例:
onclick="window.location='https://www.cindycottage.com/promozioni';return false;"
问题是按钮元素还绑定了提交事件,当您单击它时会调用该事件。 Return 错误;覆盖此默认行为;