【发布时间】:2012-02-29 22:10:53
【问题描述】:
我正在获取输入框的值并将其作为查询字符串传递给 URL。我不想获取默认值“输入关键字(地址....),它通过以下方式控制显示或隐藏:
//**onClick and OnLostFocus (focus and blur) events on textareas and input textboxes**
$('input[type="text"], textarea').focus(function () {
defaultText = $(this).val();
$(this).val('');
});
$('input[type="text"], textarea').blur(function () {
if ($(this).val() == "") {
$(this).val(defaultText);
}
});
<input name="KeywordBox" class="BasicSearchInputBox" type="text" size="300" value="Enter Keywords (address,city and state OR zipcode)"/>
如何不获取默认文本而仅获取用户输入?在 jquery 中?
【问题讨论】:
-
改用 onchange 事件并检查输入的文本是否不是默认文本。
标签: javascript jquery inputbox