单击文本框时如何在javascript

时间:2017-05-16 13:42:03

标签: javascript

当我使用提交按钮提交数据时,我得到了#34;已成功插入"消息我需要在单击文本框时清除此消息,如何清除此消息。

谢谢

2 个答案:

答案 0 :(得分:1)

为了正确地帮助您,您应该发布一些您编写的实际代码。

根据你所给出的,我可以假设你可以做到以下几点:

window.onload = function() {
    var elArr = document.querySelectorAll('input[type=text]');

    for (var i = 0, len = elArr.length; i < len; i++) {
        elArr[i].addEventListener('focus', clearText);
    }
}

function clearText() {
  document.getElementById('alert').style.display = 'none';
}
span {
  color: red;
  display: block;
}
<input id="textbox" type="text">
<input id="textbox2" type="text">
<input id="textbox3" type="text">
<input id="textbox4" type="text">
<input id="textbox5" type="text">
<span id="alert">Success!</span>

答案 1 :(得分:1)

试一下

<input id="textbox1" type="text"  onmouseenter="clearSuccessLabel()" >
<input id="textbox2" type="text"  onmouseenter="clearSuccessLabel()" >
<input id="textbox3" type="text"  onmouseenter="clearSuccessLabel()" >
<input id="textbox4" type="text"  onmouseenter="clearSuccessLabel()" >
<input id="textbox5" type="text"  onmouseenter="clearSuccessLabel()" >
<span id="alert">Success!</span>

function clearSuccessLabel() 
{
  document.getElementById('alert').innerHTML = "";
}