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

Javascript 如何将搜索输入框的值更改为用户输入值,javascript,jquery,search,Javascript,Jquery,Search,这是密码 <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'].eleme

这是密码

<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并选择搜索词(如果存在))。
如果您可以编辑服务器端代码,最好在那里进行处理。

何时保留?哪里为什么?我试过这个脚本,但它不起作用var yq=$.noConflict();yq(“#搜索输入”).submit(函数(){var txt=yq(“#搜索输入”);txt.val(“更新的”+txt.val());});您的意思是,表单提交后,页面刷新,搜索返回,然后搜索框保留原始搜索字符串。@user1881845-您的问题很难理解。请花点时间详细解释设置、预期行为和实际行为。类似于:1)我加载页面2)我在“搜索”输入字段中输入值3)我提交表单4)预期行为:以前输入的值显示在“搜索”输入字段中5)实际行为:以前输入的值不显示在“搜索”输入字段中。这正是@PatDobson上面建议的。要做到这一点,您不需要Javascript或jQuery。这需要在服务器端通过为输入字段提供属性
value=“My entered search string”
来处理,奇怪的是,jQuery现在在您的站点上不起作用。无论如何,在你的文档末尾添加这个,并告诉我它是否有效
document.getElementById('search|u input')。value=location.href.split('&search='))[1]| |'我已经编写了这个变量yq=$.noConflict();jQuery(document).ready(函数(yq){yq('search_input').submit(函数(){yq('search_input').val(location.href.split('&search='))[1]| | | | | | | | | | ; | | ; ; 59;可以吗?没有放在
ready
函数的第一行:
jQuery(document).ready(函数(yq){yq('search|u input').val(location.href.split('&search='))[1]|输入)