jquery仿京东搜索案例

HTML

<body>
<input type="button" value="搜索" id="btn">
<input type="text" name="" id="txt" value="红酒">
</body>

jquery

<script src="jQuery/jquery-1.12.3.js"></script>
    <script>
        $(function () {
            $("#txt").focus(function () {
                // 如果是默认值 清空
               if($(this).val()==="红酒") {
                   $("#txt").val("");
               }
            });
            $("#txt").blur(function () {
                // 如果为空 显示默认值
               if($(this).val()==="" ){
                   $("#txt").val("红酒");
               }
            });
        });
    </script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用jQuery仿京东购物车的示例代码: ```html <!DOCTYPE html> <html> <head> <title>jQuery仿京东购物车</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { // 添加商品到购物车 $(".add-to-cart").click(function() { var product = $(this).closest(".product"); var productName = product.find(".product-name").text(); var productPrice = product.find(".product-price").text(); var cartItem = $("<div class='cart-item'></div>"); cartItem.append("<span class='item-name'>" + productName + "</span>"); cartItem.append("<span class='item-price'>" + productPrice + "</span>"); $(".cart-items").append(cartItem); }); // 从购物车中移除商品 $(document).on("click", ".remove-from-cart", function() { $(this).closest(".cart-item").remove(); }); }); </script> <style> .product { margin-bottom: 10px; } .cart-item { margin-bottom: 5px; } </style> </head> <body> <h1>商品列表</h1> <div class="product"> <span class="product-name">商品1</span> <span class="product-price">100元</span> <button class="add-to-cart">加入购物车</button> </div> <div class="product"> <span class="product-name">商品2</span> <span class="product-price">200元</span> <button class="add-to-cart">加入购物车</button> </div> <h1>购物车</h1> <div class="cart-items"></div> </body> </html> ``` 这段代码实现了一个简单的购物车功能。当点击"加入购物车"按钮时,会将商品名称和价格添加到购物车中。购物车中的商品可以通过点击"移除"按钮来移除。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值