<form novalidate="novalidate" class="wpcf7-form" name="myForm" id="myForm">
<fieldset>
<div class="form_field odd">
<label for='desktop'>Desktops </label>
<div class="form-group">
<select id="ms" multiple="multiple">
<option value="1">Made to Order(assembled)</option>
<option value="2">HP/Compaq</option>
<option value="3">IBM</option>
<option value="4">Lenovo </option>
<option value="5">etc</option>
</select>
</div>
</div>
<div class="form_field even">
<label for='server'>Servers </label>
<div class="form-group">
<select id="ms1" multiple="multiple">
<option value="1">Made to Order(assembled)</option>
<option value="2">Compaq</option>
<option value="3">IBM</option>
<option value="4">etc</option>
</select>
</div>
</div>
<div class="form_field odd">
<label for='laptop'>Laptops </label>
<div class="form-group">
<select id="ms2" multiple="multiple">
<option value="1">HP/Compaq</option>
<option value="2">IBM</option>
<option value="3">Lenovo</option>
<option value="4">Sony</option>
<option value="5">Dell </option>
<option value="6">etc</option>
</select>
</div>
</form>
FIDDLE http://jsfiddle.net/958jm4uo/
$("select[name='qwe'] option").click(function () {
$(this).each(function () {
var label = $(this).parent().parent().parent().find('label').text();
var text = $(this).text();
alert('option text is ' + text);
alert('label text is ' + label);
});
})
UPDATE
正如@mplungjan建议的那样FIDDLE http://jsfiddle.net/958jm4uo/5/
$("select[name='qwe']").change(function () {
$(this).each(function () {
var text1 = $(this).find('option:selected').text();
var label1 = $(this).find('option:selected').parent().parent().parent().find('label').text();
alert('option text is ' + text1);
alert('label text is ' + label1);
});
UPDATE
No .parent()
with .closest('div.classnameoftheparentdiv')
FIDDLE http://jsfiddle.net/958jm4uo/7/
$("select[name='qwe']").change(function () {
$(this).each(function () {
var text1 = $(this).find('option:selected').text();
var label1 = $(this).find('option:selected').closest('div.form_field').find('label').text();//HERE parent div that contains the label has a class form_field
alert('option text is ' + text1);
alert('label text is ' + label1);
});
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)