【发布时间】:2014-09-20 21:29:52
【问题描述】:
我想使用 JS 函数的返回值作为表单获取操作的 URL。是否有可能或者我需要在 onSubmit 属性中使用函数调用来设置表单属性?
编辑:这基本上是我想要做的
<div class="search">
<form method="get" action="https://duckduckgo.com/" id="search-form">
<input id="searchbar" type="text" name="q" size="31" maxlength="255" value="" autofocus="autofocus"/>
</form>
<script type="text/javascript">
document.getElementById("search-form").action = "bang()";
</script>
</div>
bang 函数是 JS 中 DDG 的 bang 系统的实现,所以我可以轻松地将 bang 添加到我网页中的搜索框。
【问题讨论】:
-
您的意思是您有一个返回 URL 的 javascript 函数,并且在执行其他操作的过程中,您想调用该函数并设置表单的 action 属性?
-
form.action = yourFunction();会做到的。 -
我想在用户提交表单时调用该函数,并评估该函数并将其返回的 url 用于获取请求
标签: javascript html get