当选择框1的值改变时,改变选择框2的值 [英] change value of select box 2 when value of select box 1 change
本文介绍了当选择框1的值改变时,改变选择框2的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在html中有两个选择框:
< 选择 id = ostan class = DdlProvince >
< 选项 id = 1 value = test1 > test1 < / option >
< 选项 id = 2 值 = test2 > test2 < / option >
< / select >
和第二个选择框是这样的:
< select id = shahr class = DdlProvince>
< option class = 1 value = t1> t1 < / 选项 >
< option class = 1 value = t2> t2 < / 选项 >
< option class = 2 value = t3> t3 < / 选项 >
< option class = 2 value = t4> t4 < / 选项 >
< / 选择 >
我想从选择框2中显示,当选择框2的值为class =(从选择框1中选择项目ID)时变了我在jQuery中使用这段代码:
$( document )。 ready( function (){
$(' #ostan')。change( function (e){
// alert(ssss);
var optionSelected = $( 选项:选择, this )。attr(' id');
$( #shahr选项)。css(' display', none');
$(< span class =code-string> #shahr。 + optionSelected).css(' display' ,' block'); ;
}); });
我如何编辑这一行:
$ ( #shahr。 + optionSelected).css( ' display',' block'< /跨度>);
你能帮我解决一下吗?
解决方案
( document )。ready( function (){
( ' #ostan')。change( function (e){
< span class =code-comment> // alert(ssss);
var optionSelected =
( option:selected, this )。attr(' id'< /跨度>);
I have 2 select box in html like that:
<select id="ostan" class="DdlProvince">
<option id="1" value="test1">test1</option>
<option id="2" value="test2"> test2</option>
</select>
and second select box is like this:
<select id="shahr" class="DdlProvince">
<option class="1" value="t1">t1</option>
<option class="1" value="t2"> t2</option>
<option class="2" value="t3">t3</option>
<option class="2" value="t4"> t4</option>
</select>
I want shown from select box 2 just that class=(selected item id from select box 1) when value of select box 2 changed . I use this code with jQuery:
$(document).ready(function () {
$('#ostan').change( function (e) {
//alert("ssss");
var optionSelected = $("option:selected", this).attr('id');
$("#shahr option").css('display','none');
$("#shahr ."+optionSelected).css('display','block'); ;
}); });
How I can edit this line:
$("#shahr ."+optionSelected).css('display','block');
Can You help me to complet it?
解决方案
(document).ready(function () {
('#ostan').change( function (e) { //alert("ssss"); var optionSelected =
("option:selected", this).attr('id');
这篇关于当选择框1的值改变时,改变选择框2的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文