Jquery判斷搜索關(guān)鍵詞是否為空及搜索請(qǐng)求跳轉(zhuǎn)的實(shí)現(xiàn)代碼片段,以下代碼為項(xiàng)目開(kāi)發(fā)中的片段,實(shí)現(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('請(qǐng)輸入搜索關(guān)鍵詞 ...');
return false;
}
window.location.href = '//ithov.com/search/video?keyWorld=' + $keyWorld + '&identify=' + identify;
});
$(".header-search .txt").keydown(function (event) {
if (event.keyCode === 13) { //綁定回車(chē)
$('#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('請(qǐng)輸入搜索關(guān)鍵詞 ...');
return false;
}
window.location.href = '//ithov.com/search/video?keyWorld=' + $keyWorld + '&identify=' + identify;
});
$(".header-search .txt").keydown(function (event) {
if (event.keyCode === 13) { //綁定回車(chē)
$('#submit-search').click();
}
});