在注册中,我想让用户点击进入后电子邮件就自动消失。我已经添加了JS来隐藏和取消隐藏占位符文本。
代码:
<form id="form" action="https://xxxx.com/subscribe/post-json?u=xxx&id=xx&c=?" method="GET">
<input type="hidden" name="u" value="xxx">
<input type="hidden" name="id" value="xxx">
<input id="email" type="EMAIL" autocapitalize="off" autocorrect="off" name="MERGE0" id="MERGE0" size="25" placeholder= "Type your email and press enter">
<p id="response"></p>
</form>
JS代码:
<script >
var text = document.getElementById("email");
text.onfocus = function() {
if ( text.placeholder == "Type your email and press enter") {
text.placeholder = "";
}
};
text.onblur = function() {
if ( text.placeholder == "") {
text.placeholder = "Type your email and press enter";
}
};
</script>
我试图创建一个函数来触发该事件,但它不起作用:
function checkEnter(event)
{
if (event.keyCode == 13) {text.placeholder = "cool";}
};
你们能发现我的代码出了什么问题吗?