2015-08-19 38 views
0

我正在調用一個函數onclick事件select_(argum);無論我傳遞什麼值它都會在控制檯中顯示未捕獲的引用錯誤。如果我通過登錄或註冊其是跨度元件的ID然後將其傳遞ObjectHtmlSpanElement在函數中傳遞的參數顯示未捕獲的引用錯誤

<form method="post"> 
<span id="login" onClick="select_(abcd);">LOGIN</span>|<span id="signup" onClick="select_(sign)">SIGNUP</span> 
<div id="login_form"> 
<table> 
    <tr> 
     <td><input type="email" name="login_email" placeholder="Email" /></td>   
    </tr> 
    <tr> 
     <td><input type="password" name="login_password" placeholder="Password" /></td> 
    </tr> 
</table> 
</div> 
<div id="signup_form"> 
<table> 
    <tr> 
     <td><input type="text" name="fname" placeholder="First Name" /></td> 
    </tr> 
    <tr> 
     <td><input type="text" name="lname" placeholder="Last Name" /></td> 
    </tr> 
    <tr> 
     <td><input type="email" name="login_email" placeholder="Email" /></td> 
    </tr> 
    <tr> 
     <td><input type="password" name="login_password" placeholder="Password" /></td> 
    </tr> 
    <tr> 
     <td><input type="password" name="confirm_login_password" placeholder="Confirm Password" /></td> 
    </tr> 
</table> 
</div>  
</table> 
<a href="<?php echo $fb_loginUrl;?>" ><img id="facebook" src="img/fblogin.png" /></a> 
<a href="<?php echo $authUrl;?>"><img id="google" src="img/signin_button.png" /></a><br> 
</form> 
</body> 
<script> 
function _(id){ 
    return document.getElementById(id); 
} 
function select_(tabs){//Pass name of selected tab 
alert(tabs); 
    if(tabs == "abcd"){ 
     _("login_form").style.display = "block";//Display Login form 
     _("signup_form").style.display = "none";//Hides Signup Form 
    } 
    else{ 
     _("login_form").style.display = "none";//Hide Login Form 
     _("signup_form").style.display = "block";//Display Signup Form 
    } 
} 
</script> 

回答

2

參數必須withing單引號傳遞' ' 所以你可以重新寫你的跨度標記,如下所示:

<span id="login" onClick="select_('abcd');">LOGIN</span>|<span id="signup" onClick="select_('sign')">SIGNUP</span> 
1
<span id="login" onClick="select_('abcd');">LOGIN</span>|<span id="signup" onClick="select_('sign')">SIGNUP</span> 

在引號''穿戴參數。 http://jsfiddle.net/jwnek10j/ 在這種情況下,您需要字符串。

相關問題