如何添加字段';在firefox中使用javascript将s值转换为url

如何添加字段';在firefox中使用javascript将s值转换为url,javascript,cross-browser,Javascript,Cross Browser,我有一个javascript兼容性问题。此代码在Chrome中有效,但在Firefox中无效。它正在使用搜索文本中的值并将其添加到搜索url的句子 <a href="" onClick="this.href='http://localhost:8000/search?q='+search_text.value"> <input type="button" id="search-button" value="search"/> </a> 如果我删除

我有一个javascript兼容性问题。此代码在Chrome中有效,但在Firefox中无效。它正在使用搜索文本中的值并将其添加到搜索url的句子

<a href="" onClick="this.href='http://localhost:8000/search?q='+search_text.value">
    <input type="button" id="search-button" value="search"/>
</a>

如果我删除+操作符,它也可以在firefox上运行:

<a href="" onClick="this.href='http://localhost:8000/search?q='">
    <input type="button" id="search-button" value="search"/>
</a>


所以我的问题是:如何在firefox上向url添加字段中的值?谢谢你的时间。

我知道了,谢谢你的帮助!(我将修复它,我将从一位同事那里测试这段代码。)



不要使用内联Javascript!您的HTML无效。链接中不能有按钮。这将导致浏览器之间的不一致@昆汀:@elclanrs-你似乎在那张便条上发现了一个错误。“透明,但不能有交互内容后代。”@Quentin:没错,我的发现似乎有点误导,因为你认为“inline”是指任何内联元素,比如输入。这是有道理的,它是无效的。
<input type="button" id="boton-busqueda" value="Buscar" onClick="location.href='http://localhost:8000/search?q='+buscador_texto.value"/>