我有一个文本框用于输入要搜索的任何单词,并单击旁边的按钮。专注于文本框的问题
<input id="EnterText" class="lightcolor" type="text" size="50" value="Enter text" maxlength="50" name="EnterText">
<input id="ClickButton" type="image" value="Button" name="ClickButton" onclick="" src="">
当我从前端的我以为良好的用户体验设计,并进入了一个浅色一些文字Enter text
应该去更改类当焦点事件发生,回来我当模糊事件发生。因此,我为它写了jQuery。
$(document).ready(function() {
$('#EnterText').focusin(function() {
alert("focus in");
var res = document.getElementById("EnterText");
document.getElementById("EnterText").value = "";
res.setAttribute("class", "afterClick");
});
$('#EnterText').focusout(function() {
alert("focus out");
var res = document.getElementById("EnterText");
document.getElementById("EnterText").value = "Enter Text";
res.setAttribute("class", "lightcolor");
});
$('ClickButton').click(function() {
alert("Click Button")
});
});
正如你可以看到我已经尝试了focusin
,focus
,blur
和focusout
,但我不能这样做所需要的东西的那一刻我点击按钮触发事件focusout
。事实上,ClickButton
的警报从未出现。因此,我无法执行此focusout
和focusin
,现在我的想法成为了一项要求。我还注意到,当我点击文本框焦点事件先被调用,然后焦点。我需要的是一个文本框应该有一些内容引导用户,当他点击时,他会输入值,然后单击该按钮以便后端人员在获取此值后会照顾其余人员。
嘿感谢蒂亚戈,这件事情奏效。我错过了那些如果有条件和雅我找到了一个更漂亮的代码.. :) – NoviceCoder