在我的網站中,我有一個未顯示的框。當用戶輸入他的用戶名和密碼時,如果他們是正確的,則必須顯示該框。在這裏,你看到的HTML代碼:Javascript更改輸入值
<div id="mainbox" style="display: none;">
<p class="classm">Test.</p>
</div>
<input type="text" id="user"/>
<br />
<input type="text" id="password" value="a"/>
<br />
<input type="button" value="Log in" onclick="login();">
而且這裏JavaScript函數:
function login() {
var a = document.getElementById('password').value;
var b = document.getElementById('user').value;
if ((a == 'qwe') && (b == 'rty')) { //the problem is not here
document.getElementById('password').style.display="none";
}
else
{
alert('You are not logged in.');
}
}
當我點擊按鈕Log in
貌似功能login();
,因爲事情發生不叫。你知道爲什麼嗎?
你確定你是在右邊的框中鍵入正確的信嗎?第一個箱子需要'rty'和第二個'qwe'。 – putvande
工作正常:http://jsfiddle.net/5dgtz/ – Cherniv