html项目天猫商城(含有jquery)
    		       		warning:
    		            这篇文章距离上次修改已过446天,其中的内容可能已经有所变动。
    		        
        		                
                为了创建一个简单的天猫商城页面,我们可以使用HTML和jQuery来实现。以下是一个简单的示例,展示了如何创建一个包含商品列表和搜索功能的页面。
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>天猫商城</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <style>
        #product-list { list-style-type: none; }
        #product-list li { margin-bottom: 5px; }
        #product-list li.hidden { display: none; }
    </style>
</head>
<body>
 
<div class="container">
    <input type="text" id="search-box" placeholder="搜索商品">
    <ul id="product-list">
        <li>
            <span>商品A</span>
            <span>$100</span>
        </li>
        <li>
            <span>商品B</span>
            <span>$200</span>
        </li>
        <li>
            <span>商品C</span>
            <span>$300</span>
        </li>
        <!-- 更多商品... -->
    </ul>
</div>
 
<script>
    $(document).ready(function(){
        $("#search-box").on("keyup", function() {
            var value = $(this).val().toLowerCase();
            $("#product-list li").filter(function() {
                $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
            });
        });
    });
</script>
 
</body>
</html>这个页面包含一个搜索框和一个商品列表。使用jQuery,我们为搜索框添加了一个keyup事件监听器,当用户输入时,会过滤出包含搜索词的商品,并隐藏其他商品。这个简单的示例演示了如何使用jQuery来增强一个静态HTML页面的功能。
评论已关闭