[英]Added javascript and now links don't work
我添加了JavaScript以检测何时单击了链接,该链接可以正常工作,但是现在链接不起作用(即,它们不会将用户带到链接页面)。
HTML:
<div class="designflow" style="padding-left:50px;padding-right:0px;padding-top:0px;padding-bottom:15px;margin-top:0px;float:left; font-size:18px; color: gray; height:150px; width:150px;margin-left:auto;margin-right:auto;display:inline-block;">
<a href = "/manufacturing/" class = "designflow" id = "manufacturing">
<img src="{{STATIC_URL}}pinax/images/manufacturing.png" width = "150px" style=margin-bottom:0px;" alt=""><br>
<p style="position:absolute;bottom:25px;padding-left: 0px; padding-right:0px; width:150px;text-align:center;">Manufacturing</p></a>
</div>
JQUERY:
jQuery( 'div.designflow a' )
.click(function() {
do_the_click( this.id );
return false;
});
function do_the_click( designstage )
{
alert(designstage);
}
点击处理程序由于返回false禁用了它们
从事件处理程序返回false时,您告诉运行时停止对其进行处理。 这还包括停止默认操作。 在这种情况下,阻止链接成为链接。
如果您删除“返回假”行。 然后,该链接将像正常情况一样再次起作用
jQuery( 'div.designflow a' )
.click(function() {
do_the_click( this.id );
});
但是,从方法的名称中考虑,您可能确实想返回false,然后在事件处理程序中处理重定位。
在JavaScript中,您可以这样导航到新的网址:
window.location = newUrl;
这是因为您在函数中写入return false
,如果要编写它,则必须将页面重定向到javascript的链接地址
例
jQuery( 'div.designflow a' )
.click(function() {
do_the_click( this.id );
window.location="/manufacturing";
return;
});
function do_the_click( designstage )
{
alert(designstage};
}
</script>
通过在事件函数内部返回false,可以显式抑制事件的正常行为。 您应该返回true,以便在执行代码后浏览器可以正常处理该事件。
我将function
更改为返回true
jQuery( 'div.designflow a' )
.click(function() {
do_the_click( this.id );
return true;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.