gpt4 book ai didi

javascript - Jquery 在 div 中搜索一个值

转载 作者:搜寻专家 更新时间:2023-10-31 23:24:59 25 4
gpt4 key购买 nike

我有以下 div,

<div class="clinic_visit_list_entry animated fadeInUp">
<div>Hepatitis B</div>
<div>Screened: Yes</div>
<div>Treated: Yes</div>
<div>Referred: Yes British American Tobacco Kenya Clinic</div>
</div>
<div class="clinic_visit_list_entry animated fadeInUp">
<div>Hepatitis B</div>
<div>Screened: Yes</div>
<div>Treated: Yes</div>
<div>Referred: Yes British American Tobacco Kenya Clinic</div>
</div>

当我从以下 html 选择标记中选择一个值时,

<label>Select Service</label>
<select class="select_with_label" name="Service" id="select_service">
<option selected="selected">Please select</option> <option value="TB">TB</option>
<option value="Hepatitis B">Hepatitis B</option>
<option value="Hepatitis C">Hepatitis C</option>
<option value="Overdose management">Overdose Management</option>
<option value="Abscess">Abscess</option>
<option value="Alcohol & drug abuse">Alcohol & drug abuse</option>
<option value=" Cervical cancer" >Cervical cancer</option>
</select>

它应该触发以下 jquery:

$("#select_service").change(function () {
var value = $( "#select_service" ).val();
//Search through the Div for the selected value
});

如果所选值存在于 div 中,则应搜索诊所就诊条目列表。如何通过div实现搜索? (它应该只搜索已经在选择选项值中的值)

最佳答案

您可以使用 :contains选择器

Description: Select all elements that contain the specified text.

$("#select_service").change(function () {
var value = $(this).val();
var div = $('.clinic_visit_list_entry div:contains("'+value+'")');
});

JSFiddle demo

Demo with an alert (OP 对问题的评论)

关于javascript - Jquery 在 div 中搜索一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32827729/

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