躲在我有我的網頁上的2個按鈕:HTML按鈕不使用JavaScript
<button name="showLoginDiv" onclick="toggleLoginButton('button1','button2')" id="button1">Login</button><br>
<button name="showCreateDiv" onclick="toggleCreateButton('button1','button2')" id="button2">Create Account</button><br>
而這些JavaScript功能,在頁面的頂部:
function toggleLoginButton(id1, id2) {
document.getElementById(id1).style.display = 'none';
document.getElementById(id2).style.display = 'none';
// show login form
var LoginForm = document.getElementById('loginForm');
LoginForm.style.display = 'block';
}
function toggleCreateButton(id1, id2) {
document.getElementById(id1).style.display = 'none';
document.getElementById(id2).style.display = 'none';
// show create account form
var CreateForm = document.getElementById('createForm');
CreateForm.style.display = 'block';
}
當我點擊任一按鈕,我希望他們都消失,並且要顯示一個表格。第一個按鈕消失正確,但第二個按鈕沒有,窗體出現後,所以它不會卡在該行。這兩個按鈕應該消失,然後出現一個表單。 style.display = 'none'
行之一有問題。
這工作得很好:http://jsbin.com/teducipequ/edit?html,js,output –
不適合我,我會張貼截圖 – joshpj1