提问人:mentoran 提问时间:10/23/2014 更新时间:10/23/2014 访问量:943
表单操作 URL - 加到空格
Form action URL - Plus to space
问:
我的 wordpress 主题中有一个表单。我想在url中的空格中添加一个“加号”。
我的源代码:
<form method="get" id="searchform" action="/search/" onsubmit="return false;">
<input type="text" name="s" id="s" placeholder="Search" />
<input type="submit" class="submit" id="searchsubmit" value="<?php esc_attr_e( '', 'themeO' ); ?>" onclick="window.location.href=this.form.action + this.form.s.value;" />
</form>
我的实际搜索网址 - 关键字:“干得好”
http://www.example.com/search/good job
我需要这个网址:
http://www.example.com/search/good+job
答:
0赞
nicael
10/23/2014
#1
您可以使用将空格替换为加号:replace()
window.location.href=this.form.action + this.form.s.value.replace(/\s+/g,"+");
评论
0赞
mentoran
10/23/2014
window.location.href=this.form.action + this.form.s.value.replace(/\s/g,'+');这是作品,谢谢。
0赞
nicael
10/23/2014
@mentoran 如果答案有效,您可以单击投票计数下方的复选标记,使其完全绿色(称为“接受答案”)。
评论