爲什麼此功能getElementsByClassName
無法在IE7,8上工作?爲什麼這個函數getElementsByClassName不能在IE7,8上工作?
我認爲造成我的問題,從
var decimal_id_name = document.getElementsByClassName('decimal')[z_decimal].id
如何申請在IE7中,8個工作?
http://jsfiddle.net/Fp4sJ/828/
要進行測試,當用戶press button
,它會提醒輸入的ID名稱。
<form method="post" ENCTYPE = "multipart/form-data" onsubmit="return checkform(this);">
<input type="text" class="decimal" id="number0" size="20" name="number[]">
<input type="text" class="decimal" id="number1" size="20" name="number[]">
<input type="text" class="decimal" id="number2" size="20" name="number[]">
<input type="text" class="decimal" id="number3" size="20" name="number[]">
<input type="text" class="decimal" id="number4" size="20" name="number[]">
<input type="submit" name="submit" value="Next"/>
</form>
<script language="JavaScript" type="text/javascript">
function checkform (form)
{
function getElementsByClassName(node, classname) {
var a = [];
var re = new RegExp('(^|)'+classname+'(|$)');
var els = node.getElementsByTagName("*");
for(var i=0,j=els.length; i<j; i++)
if(re.test(els[i].className))a.push(els[i]);
return a;
}
var list_decimal = getElementsByClassName(document.body,'decimal');
for (z_decimal = 0; z_decimal < list_decimal.length; ++z_decimal) {
var decimal_id_name = document.getElementsByClassName('decimal')[z_decimal].id
alert(decimal_id_name);
}
return false ;
}
</script>