[英]Joomla Site - have a form that calls a javascript function - but it also is redirecting my url - why?
the code: 编码:
javascript: javascript:
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript">
function scroll(pos)
{
var x = location.hash;
var scrolamount = pos;
console.log(scrolamount);
$('html, body').animate(
{
scrollTop: scrolamount
}, 400);
var d = document.createElement("div");
d.style.height = "101%";
d.style.overflow = "hidden";
document.body.appendChild(d);
setTimeout(function ()
{
d.parentNode.removeChild(d);
}, 100);
return false;
}
</script>
html html
this function shows the alert and then returns to page as normal 此功能显示警报,然后照常返回页面
<div id="tester">
<form action="javascript:alert('action sent');" >
<input type="submit" value="But1">
</form>
this form scrolls the page as expected but then immediately redirects the URL to the main page 此表单按预期方式滚动页面,然后立即将URL重定向到主页
<div id="but1">
<form onsubmit="scroll(400)" >
<input type="submit" value="But1">
</form>
</div>
You are not preventing the form to submit. 您不会阻止表单提交。 Try adding this :
尝试添加:
onsubmit="scroll(400); return false;"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.