gpt4 book ai didi

javascript - 根据下拉值更改表单字段

转载 作者:行者123 更新时间:2023-11-28 15:09:10 25 4
gpt4 key购买 nike

我有一个 HTML,其中开头有下拉菜单,如何根据下拉值的选择更改表单字段?这是代码。

就像如果我选择常规查询,它应该显示前 2 个表单字段和常规 div 中的表单字段
如果我选择信用查询,它应该显示前 2 个表单字段以及信用 div 中的表单字段
如果我选择付款查询,它应该显示前 2 个表单字段以及付款 div 中的表单字段

 <form action="">
<select name="cases" id="cases">
<option value="general">General Inquiry</option>
<option value="credit">Credit Inquiry</option>
<option value="payment">Payment Issue</option>
</select><br>
<label for="email">Email Address <span>*</span></label>
<input type="text">
<label for="full name">Full Name <span>*</span></label>
<input type="text">


<div class="general" id="general">
<label for="documents">Wish to submit any requested documents?</label>
<input type="radio" name="radio">Yes
<input type="radio" name="radio">No <br><br>
<label for="select">How did you find out about us?<span>*</span></label><br>
<select name="case" id="case-type">
<option value="value1">Value 1</option>
<option value="value2">Value 2</option>
<option value="value3">Value 3</option>
</select><br>
</div>

<div class="credit" id="credit">
<label for="Date of Inquiry">Date of Inquiry<span>*</span></label>
<input type="date">
<label for="Agency">Agency 3 <span>*</span></label>
<input type="text">
</div>

<div class="payment" id="payment">
<label for="Service Phone Number">Service Phone Number<span>*</span></label>
<input type="text">
<label for="select">Topic<span>*</span></label><br>
<select name="case" id="case-type">
<option value="topic1">Topic 1</option>
<option value="topic2">Topic 2</option>
<option value="topic3">Topic 3</option>
</select><br><br>
</div>
<br><br>
<button>Submit</button>
</form>

最佳答案

这里的聚会迟到了,但这里有另一种方式

    // hide all the divs
$('div').hide()

// Show and hide selected div
$('#cases').change(function () {
var value = this.value;

$('div').hide()
$('#' + this.value).show();
});

还创建了一个demo

关于javascript - 根据下拉值更改表单字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37390865/

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