拍卖助推:取代.keyup功能
Auction Nudge: Replace .keyup function
我正试图使用拍卖助推代码从我的eBay商店显示项目。此代码片段在向表单中输入文本时对项进行筛选。我想做的是用静态关键字替换表单中的.keyup
函数,该关键字将在加载页面时过滤结果。
我已经尝试过修剪和修改代码,但我的jQuery知识并没有真正达到要求。
在本例中,我只想使用关键字Jiffy
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Auction Nudge Demo - Filtering By Keyword</title>
<style type="text/css">
form label {
display: block;
font-weight: bold;
}
</style>
</head>
<body>
<p>This example demonstrates how to filter a list of items shown using the column theme. Items not matching the specified keyword will be hidden. <a href="http://www.auctionnudge.com/demos/demo-filter-by-keyword.html.txt">view the source</a></p>
<form>
<label for="auction-nudge-filter">Filter</label>
<input type="text" name="auction-nudge-filter" id="auction-nudge-filter" value="Enter a keyword…" />
</form>
<script type="text/javascript" src="http://www.auctionnudge.com/item_build/js/SellerID/soundswholesale/siteid/3/theme/columns/MaxEntries/100/grid_cols/2/grid_width/100%25/show_logo/0"></script>
<div id="auction-nudge-items" class="auction-nudge"><a href="http://www.auctionnudge.com/">Live eBay Listings From Auction Nudge</a></div>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
function auction_nudge_loaded() {
var filter_cleared = false;
$(document).ready(function() {
//Clear text input on focus (only the first time!)
$('#auction-nudge-filter').focus(function() {
if (!filter_cleared) {
$(this).val('');
filter_cleared = true;
}
});
//Each time the keyword input field is updated
$('#auction-nudge-filter').keyup(function() {
var keyword = $(this).val().toUpperCase();
//Iterate over each item title
$('#auction-nudge-items td.title').each(function() {
var row = $(this).parent('tr');
var title = $(this).text().toUpperCase();
//If the title does not contain the keyword then hide the row
if (title.indexOf(keyword) == -1) {
row.hide();
$('td', row).hide();
} else {
row.show();
$('td', row).show();
}
});
});
});
}
</script>
</body>
</html>
不要调用document ready within auction loaded。文档准备好了就不会着火了
以下是脚本的修改版本,将过滤给定关键字的结果(在本例中为KEYWORD_TO_FILTER_BY
):
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Auction Nudge Demo - Filtering By Keyword</title>
<style type="text/css">
form label {
display: block;
font-weight: bold;
}
</style>
</head>
<body>
<script type="text/javascript" src="http://www.auctionnudge.com/item_build/js/SellerID/soundswholesale/siteid/3/theme/columns/MaxEntries/100/grid_cols/2/grid_width/100%25/show_logo/0"></script>
<div id="auction-nudge-items" class="auction-nudge"><a href="http://www.auctionnudge.com/">Live eBay Listings From Auction Nudge</a></div>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
function auction_nudge_loaded() {
var filter_cleared = false;
$(document).ready(function() {
var keyword = 'KEYWORD_TO_FILTER_BY';
//Iterate over each item title
$('#auction-nudge-items td.title').each(function() {
var row = $(this).parent('tr');
var title = $(this).text().toUpperCase();
//If the title does not contain the keyword then hide the row
if (title.indexOf(keyword) == -1) {
row.hide();
$('td', row).hide();
} else {
row.show();
$('td', row).show();
}
});
});
}
</script>
</body>
</html>
相关文章:
- keyup事件处理程序更改焦点不适用于快速键入
- JQuery合并了keyup和focusout两个函数
- 添加文字和评论功能更新Div
- JavaScript打印功能使日历停止工作
- 每当您在选择器内移动鼠标时,悬停功能就会重复
- 如何防止网页加载后自动启动功能
- 除修剪外的其他功能
- 悬停功能触发器
- 使用angularjs向浏览器发送servlet响应(下载功能)
- 删除CKEditor工具栏按钮,但不删除功能
- 如何在 Keyup 搜索功能中使用箭头导航进行滚动
- 保持iOS键盘打开,而keyup功能运行
- Textarea不能与jQuery live keyup功能一起工作
- keyup功能可以在所有浏览器中正常工作,但仅在IE中不起作用
- 延迟后运行keyup功能
- 问题传递空间与jquery上KeyUp功能
- Keyup功能不工作的数据表搜索
- 两个具有keyup功能的输入字段
- 拍卖助推:取代.keyup功能
- 当有人复制和粘贴时触发keyup功能