搜索功能举例
define('widget/search.js', [], function (require, exports, module) {
var _dom = {
keyword: $('.js_keyword'),
dataRole: $('.js_submit').attr('data-role'),
btn: $('.js_submit'),
};
function search() {
var type = _dom.dataRole;
var keyword = _dom.keyword.val();
if (keyword != '') {
location.href = 'http://wzy.search.xxx.com/detail/list/?filter=' + type +
'&keyword=' + keyword;
} else {
$.dialog.errorTips("请您输入搜索内容");
}
}
module.exports = {
init: function () {
$('[data-act="searcher"]').on('click', function (e) {
search();
});
}
};
//回车监听事件
$(document).keydown(function (event) {
if (event.keyCode == 13) {
search();
}
});
});
html代码
<div class="search-box fn-right js_search_container">
<div class="box">
<input type="text" name="" class="frm-input js_keyword"
placeholder="输入关键词"/>
<input type="submit" class="btn btn-primary search js_submit" data-act="searcher" data-role="series"
value="搜索"/>
</div>
</div>