0

我正在尝试使用 Auction Nudge 代码来显示来自我的 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>

4

2 回答 2

0

以下是脚本的修改版本,它将过滤给定关键字的结果(在本例中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>

于 2013-06-21T16:45:01.810 回答
0

只是不要在已加载的拍卖中调用文件准备就绪。准备好的文件不会触发

于 2013-01-07T16:50:48.463 回答