gpt4 book ai didi

jquery - JavaScript : how to change form action attribute value based on selection?

转载 作者:IT王子 更新时间:2023-10-29 03:24:13 34 4
gpt4 key购买 nike

我正在尝试根据从下拉菜单中选择的值更改表单操作。

基本上,HTML 看起来像这样:

<form class="search-form" id="search-form" method="post" accept-charset="UTF-8" action="/search/user">
<select id="selectsearch" class="form-select" name="selectsearch">
<option value="people">Search people</option>
<option value="node">Search content</option>
</select>

<label>Enter your keywords: </label>
<input type="text" class="form-text" value="" size="40" id="edit-keys" name="keys" maxlength="255" />

<input type="submit" class="form-submit" value="Search" id="edit-submit" name="search"/>
</form>

如果选择“people”(默认情况下),则操作应为“/search/user”,如果选择内容,则操作应为“/search/content”

我还在四处寻找,但一直没能找到如何做到这一点。

最佳答案

$("#selectsearch").change(function() {
var action = $(this).val() == "people" ? "user" : "content";
$("#search-form").attr("action", "/search/" + action);
});

关于jquery - JavaScript : how to change form action attribute value based on selection?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1925614/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com