二级联动,div id取javascript动态值,javascript是取select的值。
<scriptlanguage="javascript">functiona(obj){var_selectedvalue=obj.value;if(_selectedv...
<script language="javascript">
function a(obj){
var _selectedvalue = obj.value;
if(_selectedvalue==''){
_selectedvalue = '-1';
}
for(i=1;i<=30;i++){
var divobj = document.getElementById('tb'+i);
if(parseInt(_selectedvalue)==i){
divobj.style.display = 'block';
}else{
divobj.style.display = 'none';
}
}
}
</script>
<select class="ge" id='selecttb' onchange="a(this)">
<option value='1'>Any</option>
<option value='5'>Any2</option>
<option value='7'>Any3</option>
</select>
<div id="tb1" size="1" style='display:none'>
<select name="manufaturer" size="1" class="ge"id="manufaturer">
<option value="1">re5</option>
<option value="2">re6</option>
<option value="7">re7</option>
</select>
</div>
想取divobj 动div id中。要动态的。divobj 变了,div id也跟着变。无刷新那种。请高手帮解。 展开
function a(obj){
var _selectedvalue = obj.value;
if(_selectedvalue==''){
_selectedvalue = '-1';
}
for(i=1;i<=30;i++){
var divobj = document.getElementById('tb'+i);
if(parseInt(_selectedvalue)==i){
divobj.style.display = 'block';
}else{
divobj.style.display = 'none';
}
}
}
</script>
<select class="ge" id='selecttb' onchange="a(this)">
<option value='1'>Any</option>
<option value='5'>Any2</option>
<option value='7'>Any3</option>
</select>
<div id="tb1" size="1" style='display:none'>
<select name="manufaturer" size="1" class="ge"id="manufaturer">
<option value="1">re5</option>
<option value="2">re6</option>
<option value="7">re7</option>
</select>
</div>
想取divobj 动div id中。要动态的。divobj 变了,div id也跟着变。无刷新那种。请高手帮解。 展开
2个回答
展开全部
关键词:selectedIndex(所选键值)
obj[obj.selectedIndex].value 才是所选 option 的值
<script language="javascript">
function a(obj){
var _selectedvalue = obj[obj.selectedIndex].value;
if(document.getElementById("tb" + _selectedvalue) !== null) {
for(var i = 1; i < 30; i++) {
if(document.getElementById("tb" + i) !== null) {
document.getElementById("tb" + i).style.display =
i == _selectedvalue ? "block" : "none";
}
}
}
}
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询