我目前在我的html文件中設置了2個按鈕。使用javascript創建輸入字段
<div class="login-register">
<button type="button" id="login" onclick="login()">Login</button>
<button type="button" id="register">Register</button>
</div><!-- end of login-register -->
我想將這些按鈕與JavaScript結合使用,以便在登錄時單擊。然後按鈕被隱藏,並且2個輸入字段如
<input id="username" type="text" name="username" placeholder="Username">
<input id="password" type="text" name="password" placeholder="Password">
出現。我使用的是內部腳本標籤和所有我到目前爲止,
$("#login").click(function(){
var usernameInputField = document.createElement("login");
usernameInputField.setAttribute('type', 'text');
usernameInputField.setAttribute('placeholder', 'Username');
usernameInputField.setAttribute('name', 'username');
})
我不知道這是很好的做法,或者如果有另一種首選方法來設置此。
的創建的createElement不是 '登錄' 的輸入,那麼它的好。 – baao