如何在firefox中使用javascript为url添加字段值

How to add a field's value to a url in firefox using javascript

本文关键字:url 添加 字段 javascript firefox      更新时间:2023-09-26

我有一个javascript兼容性问题。这段代码可以在Chrome中工作,但不能在Firefox中工作。它使用search-text中的值并将其添加到搜索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 ?感谢您的宝贵时间。

我明白了,谢谢你的帮助!(我会修复它,我正在从同事那里测试这段代码。)

<input type="button" id="boton-busqueda" value="Buscar" onClick="location.href='http://localhost:8000/search?q='+buscador_texto.value"/>