IE在组合框中未显示所选值 [英] IE not showing selected value in Combo Box

查看:83
本文介绍了IE在组合框中未显示所选值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的网页中有两个选择控件(第一个名为"type",第二个名为"ht".当第一个的值更改时,下面的选择控件将通过Javascript重新填充.

代码如下:



I''ve two select controls in my webpage (first named "type", second named "ht". When the value of the first changes, the select control just below is re-populated via Javascript.

Here''s the code:

function ableht ()
{

var combo;

var combo = document.srch.ht;

if (document.srch.type.value=="Homes")
{

document.srch.ht.options.length = 0;
combo.options[0] = new Option ("Any Type");
combo.options[1] = new Option ("Houses");
combo.options[2] = new Option ("Flats");
combo.options[3] = new Option ("Upper Portions");
combo.options[4] = new Option ("Lower Portions");
combo.options[5] = new Option ("Farm Houses");

}

else if (document.srch.type.value="Plots")

{

document.srch.ht.options.length = 0;
combo.options[0] = new Option ("Any Type");
combo.options[1] = new Option ("Residential Plots");
combo.options[2] = new Option ("Commercial Plots");
combo.options[3] = new Option ("Agricultural Land");

}

else 

{

document.srch.ht.options.length = 0;
combo.options[0] = new Option ("Any Type");
combo.options[1] = new Option ("Offices");
combo.options[2] = new Option ("Shops");
combo.options[3] = new Option ("Warehouses");
combo.options[4] = new Option ("Factories");
combo.options[5] = new Option ("Buildings");
combo.options[6] = new Option ("Other");

}
}




和HTML:




And the HTML :

Property Type: <select name="type" style="width:170px" onchange="ableht ()">
  <option>Homes</option>
  <option>Plots</option>
  <option>Commercial</option>
</select>



当页面加载时,IE会显示应该选择的第一个组合框的第一个值.问题是,当我从第一个选择框选择任何值时,IE中没有选择该值.该字段为空白,也不会重新填充第二个选择框.它在Chrome上正常运行,但是IE引起了问题.

有任何解决方法的想法吗?

谢谢!



When the page loads, IE shows the first value of the first combo box selected, which it should.The problem is that when I select any value from the first select box, it is not selected in IE. The field is blank and it also does not re-populate the second select box. It works fine on Chrome, but IE is causing problem.

Any ideas how to fix it?

Thanks!

推荐答案

不太确定如何解决-因为IE中的调试器有些不足.

此代码可在IE8中使用-无需7即可进行测试.

Not quite sure how to fix it - since the debugger in IE leaves a little to be desired.

This code works in IE8 - don''t have 7 to test with.

<!DOCTYPE html>
<html>
  <head>
  <script>
	function byId(e) {return document.getElementById(e);}
	
	function stateComboChange()
	{
		var combo1 = byId('stateCombo');
		var combo2 = byId('cityCombo');
		
		emptyCombo(combo2);
		switch(combo1.value)
		{
			case '-1': 	addOption(combo2, -1, '-select state first-');
						break;
						
			case '0':	addOption(combo2, 0, 'Melbourne');
						addOption(combo2, 1, 'Horsham');
						break;
						
			case '1':	addOption(combo2, 2, 'Sydney');
						addOption(combo2, 3, 'Bondi');
						break;
						
			case '2':	addOption(combo2, 4, 'Hobart');
						addOption(combo2, 5, 'Port Arthur');
						break;
		}
		cityComboChange();
	}
	
	function cityComboChange()
	{
		var combo2, tgt;
		combo2 = byId('cityCombo');
		tgt = byId('tgt');
		
		tgt.innerHTML = combo2.options[combo2.options.selectedIndex].title;
	}
	
	function emptyCombo(e)
	{
		e.innerHTML = '';
	}
	
	function addOption(combo, val, txt)
	{
		var option = document.createElement('option');
		option.value = val;
		option.title = txt;
		option.appendChild(document.createTextNode(txt));
		combo.appendChild(option);
	}
	
  </script>
  </head>
  <body>
	<select id='stateCombo' onchange='stateComboChange();'>
		<option value='-1' title='-select one-'>-select one-</option>
		<option value='0' title='Vic'>Vic</option>
		<option value='1' title='Nsw'>Nsw</option>
		<option value='2' title='Tas'>Tas</option>
	</select>
	
	<select id='cityCombo' onchange='cityComboChange();'>
		<option value='-1' title='-select state first-'>-select state first-</option>
	</select>
	
	<div id='tgt'></div>
</body>
</html>


这篇关于IE在组合框中未显示所选值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆