我试图在Javascript变量有值后将表单中的输入类型从“隐藏”更改为“文本”。我目前的代码是:
var currentUser;
var getButton = document.getElementById("button");
getButton.addEventListener("click",getUser,false);
function getUser(event) {
var user = document.getElementById("username");{
if(user.value !=="") {
currentUser = user.value;
}
event.preventDefault();
}
if(currentUser.value!=="") {
document.getElementById("message").type="text";
}
}
我的HTML是这样的:
<form method = "post">
{% if username %}
<label>{{ username }}</label>
<input id="message" type="text" size="70" name="message" />
<input type="hidden" name="username" value="{{ username }}" />
<input type="hidden" name="timestamp" value="{{ timestamp }}" />
{% else %}
<label>Pick a username: </label>
<input type="text" size="10" name="username" id="username" />
{% endif %}
<input type="submit" value="send" id="button" />
</form>
</div>
谁能告诉我哪里出错了?目前,每当我运行代码时,它都会卡在“用户名”上,并且“消息”框不会出现。