2015-10-05 23 views
0

即使在onclick返回true之後,我仍然遇到鏈接不存在的問題。它在Chrome和Firefox中運行良好。我注意到只有錨的這一特定行爲是tag.I現在用引導的反應(不知道這是影響..)即使在onclick =「return true;」之後,IE11並沒有跟蹤鏈接

樣品:

<form> 
<a id="SignonButton" class="SignonButton" HREF="https://www.google.com" onClick="return true;"> 
    <button type="button" class="btn btn-primary" id="button1" name="button1">Inside form doesnt work</button> 
     </a> 
</form> 

<a id="SignonButton" class="SignonButton" HREF="https://www.google.com" onClick="return true;"> 
    <button type="button" class="btn btn-primary" id="button1" name="button1">Outside form works</button> 
     </a> 

@TJ確實是這樣,它的工作。 其實我改造現有一個形式,使之響應的形式具有兩個動作和兩個輸入元素 1. HREF =「使用Javascript:transferRequest()」 2.的onClick =「validateRequest()」

形式具有兩個輸入元素input1:email和input2:密碼。

什麼我可以從現有代碼不解的是,validateeRequest()驗證電子郵件方式([email protected])和密碼alphanum模式並返回true

如果兩個模式相匹配。

驗證請求檢查兩個文本框以確認輸入的文本相匹配的圖案或沒有(不驗證只是檢查,如果模式匹配與否,轉印

請求實際上兩個文本傳送,因爲它是服務器)。

建議使用<a>爲按鈕是正確的,或者我需要添加驗證方法到按鈕 我不允許完全修改網站,只是將其轉換爲響應。

<div> 
    <label for="email">Email</label> 
    <input type="TEXT" size="16" maxlength="19" autocomplete="OFF"> 
</div> 
<div> 
    <label for="Password" >Password</label> 
    <input type="PASSWORD" size="16" maxlength="19" autocomplete="OFF> 
</div> 
<div> 
    <a id="SignonButton" HREF="javascript:transferRequest('verify')" onClick="return ValidateRequest('Verify');"> 
    <button type="button" class="btn btn-primary" id="button1" name="button1">Inside form doesnt work</button> 
     </a> 
</div> 
</form> 


function transferRequest() 
{ 

var form = document.loginForm; 
document.loginForm.submit();//submits to local exchange server 
//some crazy validation 
} 

function validateRequest() 
{ 
// code to check if the email input follows pattern ([email protected]) or not 
// code to check if the password has alphanum as pattern or not 
//return true if both pattern matches 
} 
+0

可能是由於一個互動的元素(''

回答

0

你不能有一個button一個鏈接裏面。這是invalida的內容模型

透明的,但必須有沒有interactive content後裔。

因爲它是無效的,瀏覽器可以自由地做任何它認爲應該做的事情,包括重定位鏈接外的按鈕。

另外,return trueonClick沒有任何影響。 (return false有,但不是return true。)

因此,您需要做的是修改您的內容以使其有效。那麼它可能正確地跨瀏覽器工作。由於您使用的引導,兩個選擇有:

  1. 擺脫button完全的:

    <a id="SignonButton" class="btn btn-primary SignonButton" href="https://www.google.com">Click Me</a> 
    

    這看起來像的,因爲引導樣式的按鈕。

  2. 擺脫完全鏈接:

    <button type="button" id="SignonButton" class="SignonButton btn btn-primary" onclick="location = 'http://www.google.com'>Click Me</button> 
    

#1會被強烈的首選,因爲它是一個鏈接後所有。

+1

@TJ感謝一噸,這工作非常好 – pathruds

0

將按鈕從標籤中取出。如前所述,這是無效的。使用這樣的事情:一個錨的內

<button type="button" class="btn btn-primary" id="button1" name="button1" onclick="window.location='http://www.google.com';">Inside form should work. ;)</button>