如何将搜索输入框的值更改为用户输入值

How to change the value of search input box to the user input value

本文关键字:输入 用户 搜索      更新时间:2023-09-26

这是代码

<form class="navbar-search pull-right header-link" method="post" name="searchportlet" id="searchportlet" onsubmit="window.location.href='/s.nl?ext=F&amp;sc=22&amp;category=&amp;search='+escape(document.forms['searchportlet'].elements['search'].value);return false;">
    <div class="dowith clearfix">
        <a href="#" class="left" onclick="window.location.href='/s.nl?ext=F&sc=22&category=&search='+escape(document.forms['searchportlet'].elements['search'].value);return false; return false;">
            <img alt="" src="/images/search.png" style="margin-top: 5px;">
        </a>
        <input name="search" type="text" onsubmit="window.location.href='/s.nl?ext=F&sc=22&category=&search='+escape(document.forms['searchportlet'].elements['search'].value);return false; return false;" onfocus="if (this.value == 'Search entire store...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search entire store...';}" value="Search entire store..." class="right textfield" id="search_input">
    </div><!--End dowith-->
</form>

如何保留用户输入的搜索输入文本。我需要js或jquery中的解决方案.表单提交搜索后,整个存储值必须替换为用户输入的文本

查看您的网站,有以下部分在您的页面加载后执行:

jQuery(document).ready(function($) {

在下面添加类似这样的东西:

$('#search_input').val(location.href.split('&search=')[1] || '');

这不是一个好的解决方案(基本上读取 URL 并选择搜索词(如果存在)。如果可以编辑服务器端代码,最好在那里处理它。