-1

我有几个复选框和一个输入框。用户可以勾选复选框或/也可以键入关键字。如果用户未在输入框中键入任何内容,则应仅将复选框值传递给 url。如果用户在 inout 框中输入 sth,它也应该传递输入框的值。就我而言,它还在输入框中获取默认文本“输入关键字”。我如何排除它并只接受用户输入?

<div class="LocationSearchBox">
    <input name="KeywordBox" class="BasicSearchInputBox" type="text" size="300" value="Enter Keyword"/> 
    <div class="searchBtnHolder"><a class="searchButton" href="#" type="submit"><span>Search</span></a></div>
</div>

我就这么远。。

if (keywords.indexOf("Enter Keywords"))
                 {
                    window.location= url+checkboxValues;
                 }

                if (keywords.indexOf("Enter Keywords") == -1)
                 {
                    window.location= url+keywords+'*'+checkboxValues;
                 }
4

1 回答 1

0

为什么不考虑清空默认值 onfocus 并在其值为空时将其分配回 onblur ?

var keyW = $("input[name='KeywordBox']");
keyW.data('initVal',keyW.val());
keyW.focus(function() {
    if ($(this).val() == $(this).data('initVal')) $(this).val('');
});
keyW.blur(function() {
    if (/^\s*$/.test($(this).val())) $(this).val($(this).data('initVal'));
});
于 2012-03-01T00:37:55.783 回答