簡體   English   中英

Joomla網站-具有調用javascript函數的形式-但它也正在重定向我的網址-為什么?

[英]Joomla Site - have a form that calls a javascript function - but it also is redirecting my url - why?

編碼:

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

此功能顯示警報,然后照常返回頁面

<div id="tester">
<form action="javascript:alert('action sent');" >
<input type="submit" value="But1">
 </form>

此表單按預期方式滾動頁面,然后立即將URL重定向到主頁

<div id="but1">
 <form  onsubmit="scroll(400)" >
<input type="submit" value="But1">
          </form>       
</div>

您不會阻止表單提交。 嘗試添加:

onsubmit="scroll(400); return false;"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM