淘宝/天猫如何自定义页面页头元素的搜索框代码

如图,这样的效果:

在页面的顶部加入搜索框。

无论是淘宝还是天猫都可以,但是代码有一些区别,编码不一样。

下面是代码展示:

淘宝

<div
style="background:none;border:0;padding:0;width:1920px;height:880px;position:relative;top:0;left:0;right:0;background-image:url(990*120的背景图片地址);background-repeat:no-repeat;background-attachment:scroll;">
<div class="keywords sform"
    style="width: 198px; height: 25px; overflow: hidden; bottom: -5%; left: 34%; padding: 0; background-image: url(200*25的单独的搜索框地址); position: relative; display: flex;">
    <form action="店铺首页地址" method="get" target="_blank"
        style="display: flex; width: 100%;height: 100%;">
        <input name="search" type="hidden" value="y" />
        <input class="keyword-input prompt" name="keyword" type="text"
            style="width: 76%; height: 100%; background: transparent; border: none; outline: none;padding-left: 6%;" />
        <input class="btn" type="submit" value="搜索"
            style="opacity: 0;width: 16%; height: 100%; font-size: 12px; cursor: pointer; border: none; outline: none;" />
    </form>
</div>
</div>

解释一下上面的代码:

第一个div是背景图片。

第二个的div是搜索框。搜索框是透明的。

你要修改的地方是

1.(990*120的背景图片地址)

2.(200*25的单独的搜索框地址)

3.action="店铺首页地址"

这三个地址,前两个是图片空间,你直接去复制即可,第三个是装修页面的地址即可。

其中,核心代码是:

<input name="search" type="hidden" value="y" />

一定不要删除这个,其他可以自行修改。

天猫

<div
    style="background:none;border:0;padding:0;width:1920px;height:880px;position:relative;top:0;left:0;right:0;background-image:url(990*120的背景图片地址);background-repeat:no-repeat;background-attachment:scroll;">
    <div class="keywords sform"
        style="width: 198px; height: 25px; overflow: hidden; bottom: -5%; left: 34%; padding: 0; background-image: url(200*25的单独的搜索框地址); position: relative; display: flex;">
        <form class="J_TCrumbSearchForm" accept-charset="ASCII" action="店铺首页地址"
            method="post" style="display: flex; width: 100%;height: 100%;">
            <input name="search" type="hidden" value="y" />
            <input type="text" class="crumbSearch-input J_TCrumbSearchInuput" value="" name="keyword"
                style="width: 76%; height: 100%; background: transparent; border: none; outline: none;padding-left: 6%;" />
            <input class="crumbSearch-btn J_TCrumbSearchBtn" type="submit" value="搜索"
                style="opacity: 0;width: 16%; height: 100%; font-size: 12px; cursor: pointer; border: none; outline: none;" />
        </form>
    </div>
</div>

注意事项:

基本上和上面淘宝的代码一样,只不过是form表单里面要加上accept-charset="ASCII",转换一下编码,即可。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值