<div id="abc" class="first">
<input type="text" placeholder="Number" id="no" class="contact">
<input type="text" placeholder="Pass" id="pass" class="password">
<div class="btn1" role="group">
<button type="button" onclick="change()" class="btnregi">Register
</button>
</div>
----------
javascript function
var entry=0;
function change()
{
if(entry==0)
{
document.getElementById("no").placeholder = "Enter user name...";
document.getElementById("pass").placeholder = "Enter user password";
entry++;
}
else
{
var newuser=document.getelementById("no").value;
var newpass=document.getelementById("pass").value;
alert("you entered new username"+newuser);
alert("you entered new password"+newpass);
}
我想更改占位符值onclick事件,并再次使用相同的按钮单击和方法我想要获取输入数据。我附上了我的代码,但它无法正常工作。
答案 0 :(得分:1)
你在这两行中拼错了getElementById
。除此之外,代码似乎对我很好。
var newuser = document.getElementById("no").value;
var newpass = document.getElementById("pass").value;
var entry = 0;
function change() {
if (entry == 0) {
document.getElementById("no").placeholder = "Enter user name...";
document.getElementById("pass").placeholder = "Enter user password";
entry++;
} else {
var newuser = document.getElementById("no").value;
var newpass = document.getElementById("pass").value;
alert("you entered new username: " + newuser);
alert("you entered new password: " + newpass);
}
}
&#13;
<div id="abc" class="first">
<input type="text" placeholder="Number" id="no" class="contact">
<input type="text" placeholder="Pass" id="pass" class="password">
<div class="btn1" role="group">
<button type="button" onclick="change()" class="btnregi">Register
</button>
</div>
&#13;