2015-10-05 22 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>