我有一个简单的输入表单。
<div id="inputboxforemailandpassword">
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
</div>
<hr>
<div id="apistatusmessage">
<p>loading...</p>
</div>
<button id = "buttonregister" class="btn btn-lg btn-primary btn-block" onclick="registration()" >
register
</button>
<button id = "clearinput" class="btn btn-lg btn-primary btn-block" onclick="clearouttheinputboxes()" >
clearinput
</button>
这是我正在使用的明确功能。
function clearouttheinputboxes()
{
var logopener="----entering clearouttheinputboxes----";
console.log(logopener);
//collect the email address and password.
var emailaddress = document.getElementById("inputEmail");
var password = document.getElementById("inputPassword");
emailaddress.setAttribute('value', "");
password.setAttribute('value', "");
var logcloser="----leaving clearouttheinputboxes----";
console.log(logcloser);
}
我已经在我的代码笔上复制了这个,在这里。
https://codepen.io/jay-pancodu/pen/oNbVrVV
问题是这样的。
a) 在 codepen 上,完全相同的代码可以很好地清除输入框。b)在我的网络应用程序上,无论我尝试清除多少次以及我在值中使用哪个值,输入框都会保留。
那么,我在这里做错了什么。
更新 1 - 很多评论建议我使用类似这样的东西
password.value = "some value";
这并不能解决我的问题。请检查我是否在 codepen 中获得了输出。不想使用 .value 方法。
更新 2 - 看起来 CodePen 代码也不起作用
更新 3 - 在 CodePen 上重现问题
能够在输入任何内容之前设置和清除输入框。但是一旦你在框中输入,设置和清除值的能力就会丢失
德玛西亚99
慕田峪7331174
侃侃无极
倚天杖
相关分类