Jquery判斷搜索關鍵詞是否為空及搜索請求跳轉(zhuǎn)的實現(xiàn)代碼片段,以下代碼為項目開發(fā)中的片段,實現(xiàn)方法思路僅供參考。
//搜索
$('#submit-search').on('click', function () {
var $keyWorld = $(".header-search .txt").val();
$keyWorld = $.trim($keyWorld);
var identify = $('#search-identify').val();
if ($keyWorld.length <= 0) {
alert('請輸入搜索關鍵詞 ...');
return false;
}
window.location.href = '//ithov.com/search/video?keyWorld=' + $keyWorld + '&identify=' + identify;
});
$(".header-search .txt").keydown(function (event) {
if (event.keyCode === 13) { //綁定回車
$('#submit-search').click();
}
});
//搜索
$('#submit-search').on('click', function () {
var $keyWorld = $(".header-search .txt").val();
$keyWorld = $.trim($keyWorld);
var identify = $('#search-identify').val();
if ($keyWorld.length <= 0) {
alert('請輸入搜索關鍵詞 ...');
return false;
}
window.location.href = '//ithov.com/search/video?keyWorld=' + $keyWorld + '&identify=' + identify;
});
$(".header-search .txt").keydown(function (event) {
if (event.keyCode === 13) { //綁定回車
$('#submit-search').click();
}
});