L?I: Internet Explorer khng thnh cng ? thi?t l?p innerHTML ti s?n c?a ?i t?ng ch?n

D?ch tiu ? D?ch tiu ?
ID c?a bi: 276228
Bung t?t c? | Thu g?n t?t c?

? Trang ny

TRI?U CH?NG

Khi b?n ?t thu?c tnh innerHTML c?a ch?n ?i t?ng, nh?ng thay ?i khng c hi?u l?c m?t cch chnh xc.

GI?I PHP

N?u b?n ph?i s? d?ng innerHTML, m?t workaround l s? d?ng m?t ?i t?ng Div ? b?c cc y?u t? l?a ch?n v sau thi?t l?p innerHTML ti s?n cho ?i t?ng Div . V d?:
<html>
<head>
<title>My Example</title>
<script language="Javascript">
var origDivHTML;

function init()
{
   origDivHTML = myDiv.innerHTML;
}

function setValues() 
{
   var oldinnerHTML = "your original innerHTML: " + yourDiv.innerHTML ; 	
   alert(oldinnerHTML);
   yourDiv.innerHTML = origDivHTML;
	 
   var curinnerHTML = "your current innerHTML: " + yourDiv.innerHTML ; 
   alert(curinnerHTML); 
}
</script>
</head>

<body onload="init()">

<div id="myDiv">
  <select name="firstSelect" size="1" >
    <option>11111</option>
    <option>22222</option>
    <option>33333</option>
  </select>
</div>

<div id="yourDiv">
  <select name="secondSelect" size="1" >
    <option>aaaa</option>
    <option>bbbb</option>
    <option>cccc</option>
  </select>
</div>
<button onclick = "setValues();">click me to set the values</button>
</body>
</html>
				

L? t?ng nh?t, b?n nn s? d?ng cc b? su t?p ty ch?n ? thm cc ty ch?n c?a m?t y?u t? l?a ch?n. Cc m? sau y cho th?y ba cch ? l?p tr?nh thm l?a ch?n vo cc y?u t? l?a ch?n:
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>

<script>

function fill_select1() {

	for(var i=0; i < 100; i++) {
			select1.options[i] = new Option(i,i);
		}
}

function fill_select2() {

		var sOpts = "<SELECT>";
		for (var i=0;i<100;i++)
		{
			sOpts += '<OPTION VALUE="' + i + '">' + i + '</OPTION>\n';
		}
	
		select2.outerHTML = sOpts  + "</SELECT>";
}

function fill_select3() {

	for(var i=0; i < 100; i++) {
		   var oOption = document.createElement("OPTION");
		   oOption.text="Option:  " + i;
		   oOption.value=i;
		   document.all.select3.add(oOption)
		}
}



</script>

<H2>SELECT Box Population</H2>

<SELECT id=select1 name=select1></SELECT>
<INPUT type="button" value="Populate with options list" id=button1 
name=button1 onclick="fill_select1();"><BR><BR>
<SELECT id=select2 name=select2></SELECT> 
<INPUT type="button" value="Populate with outerHTML" id=button2 
name=button2 onclick="fill_select2();"><BR><BR>
<SELECT id=select3 name=select3></SELECT>
<INPUT type="button" value="Populate with using createElement" id=button3 
name=button3 onclick="fill_select3();">

</BODY>
</HTML>
				

T?NH TR?NG

Microsoft ? xc nh?n r?ng y l m?t l?i trong cc s?n ph?m c?a Microsoft ?c li?t k ? ?u c?a bi vi?t ny.

THNG TIN THM

Cc b?c ? t?o l?i hnh vi

M?u m? sau y minh h?a l?i ny:
<html>
<head>
<script language="JavaScript">  
function test()
{
    var objSelect = document.all.idSelect;
    var strOrigHTML     = objSelect.innerHTML;
    objSelect.innerHTML = strOrigHTML;
    var strNewHTML      = objSelect.innerHTML;

    if (strNewHTML == strOrigHTML)
        alert("Test passed.");
    else
        alert("Test failed: innerHTML = " + strNewHTML );
}
</script>
</head>
<body>
  <select id="idSelect">
    <option value="line1">Option 1</option>
    <option value="line2">Option 2</option>
  </select>
  <input type="button" value="test" onClick="test()" />
</body>
</html>
				

THAM KH?O

? bi?t thm chi ti?t trn ch?n ?i t?ng, xem cc bi vi?t sau y trn m?ng nh pht tri?n Microsoft (MSDN):
Ch?n ?i t?ng
? bi?t thm chi ti?t v? b? su t?p ty ch?n , xem bi vi?t sau y trn MSDN:
Ty ch?n b? su t?p

Thu?c tnh

ID c?a bi: 276228 - L?n xem xt sau cng: 17 Thang Nm 2012 - Xem xt l?i: 4.0
T? kha:
kbbug kbdhtml kbnofix kbmt KB276228 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:276228
Khc t Ni dung trong C s Kin thc Khng con c h tr
Bi vi?t ny ni v? cc s?n ph?m m Microsoft khng c?n h? tr? n?a. Do , bi vi?t ny ?c cung c?p "nguyn b?n" v s? khng ?c c?p nh?t.

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com