gpt4 book ai didi

jquery - 将下拉选择上的单选按钮选择传递给 URL 中的查询字符串

转载 作者:行者123 更新时间:2023-12-01 03:51:19 25 4
gpt4 key购买 nike

我有两列单选按钮和一个用于其他选择的下拉菜单。两个控件都是同一项目的选择,例如本例中的“专业”。如果选择了左列或右列中的单选按钮之一,或者如果选择了下拉列表,则如何从单选按钮获取所选值被选中并将该选择作为查询字符串传递到 URL?因此,如果从单选按钮中选择心脏病专家,我想将其传递到网址

/search/pages/physicians.aspx?v=relevance&s=Physicians&k=Cardiologist

或者如果从下拉列表中选择了 number1,则附加到 url

/search/pages/physicians.aspx?v=relevance&s=Physicians&k=number1

如何在jquery中做到这一点?

<div class="Specialty-Choices"><span class="Choices-Title">Choose a Specialty</span><br /><br />
<div class="radioHolder">
<div class="radioCol-left">
<div class="radioRow"><input name="speciality_type" type="radio" value="Cardiologist"/> <label>Cardiologist</label> </div>
<div class="radioRow"><input name="speciality_type" type="radio" value="Dermatologist"/> <label>Dermatologist</label> </div>
<div class="radioRow"><input name="speciality_type" type="radio" value="Family Physician"/> <label>Family Physician</label> </div>
<div class="radioRow"><input name="speciality_type" type="radio" value="Gastroenterologist"/> <label>Gastroenterologist</label> </div>
<div class="radioRow"><input name="speciality_type" type="radio" value="Neurologist"/> <label>Neurologist</label> </div>
</div>
<div class="radioCol-right">
<div class="radioRow"><input name="speciality_type" type="radio" value="Obstetrician"/> <label>Obstetrician</label> </div>
<div class="radioRow"><input name="speciality_type" type="radio" value="Orthopedic Surgeon"/> <label>Orthopedic Surgeon</label> </div>
<div class="radioRow"><input name="speciality_type" type="radio" value="Pediatrician"/> <label>Pediatrician</label> </div>
<div class="radioRow"><input name="speciality_type" type="radio" value="Primary Care Doctor"/> <label>Primary Care Doctor</label> </div>
<div class="radioRow"><input name="speciality_type" type="radio" value="Psychiatrist"/> <label>Psychiatrist</label> </div>
</div>
</div><br />
<div class="mainPaneRow clearfix"><span class="inp"><select id="landing_physician_specialty"> <option disabled="disabled" selected="selected">Select other specialty</option> <option>--number-1--</option> <option>--number-2--</option> <option>--number-3--</option></select> </span></div>
<div class="mainPaneRow clearfix"><div class="submitBox"><a class="btnBlue" href="#" type="submit"><span><em class="searchElem">Search</em></span></a> <a class="paneBoxLink" href="/physicians/">Advanced Search</a> </div></div>
</div><!--END Specialty-Choices-->

最佳答案

获取选定的单选按钮:

var selectedDoctorType = $("input[name='speciality_type']:checked").val();

获取选定的下拉值:

var selectedNum = $("#landing_physician_specialty").val();

将它们放入 URL 中应该只需进行一些字符串连接即可

var baseUrl = "search/pages/physicians.aspx?v=relevance&";

if (selectedDoctorType)
baseUrl += "s=" + selectedDoctorType + "&";
if (selectedNum)
baseUrl += "v=" + selectedNum;

请注意,我的解决方案中可能尾随的 amersand 是 perfectly valid

关于jquery - 将下拉选择上的单选按钮选择传递给 URL 中的查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8389115/

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