Javascript .click()逐个元素无法正常工作

时间:2014-10-23 16:52:41

标签: javascript jquery

我有一个输入,用于使用jQuery和函数“performSearch()”搜索我的网站,现在它仅在使用.keypress()使用jQuery函数时才有效。它应该与.click()一起工作。我错过了什么?

//Search controls
function performSearch(context) {
    var searchVal = encodeURIComponent($('input[type=text]', context).val());
    var url = "/search.aspx?q=" + searchVal;
    window.location = url;
}

$(document).ready(function () {

    $('.search-box input[type=submit]').click(function () {
        performSearch($(this).parent());
    });
    $('.search-box input[type=text]').keypress(function (event) {
        if (event.keyCode == 13) {
            performSearch($(this).parent());
            return false;
        }
        return true;
    });

});

0 个答案:

没有答案
相关问题