想讓Label都顯示相同值,直接抓ClassName一次改,
查了資料,Javascript 有 document.getElementsByClassName
但有些遊覽器不支援,所以要另外寫一段function
用這個慨念,就能寫出更多的function來用
var s = document.getElementsByClassName("123");
for (i = 0; i < s.length; i++) {
s[i].innerHTML = "123";
}
所以要用迴圈
用來改變ASP.NET網頁裡所有的Label值
if (!document.getElementsByClassName) {
document.getElementsByClassName = function (className, element) {
var children = (element || document).getElementsByTagName('*');
var elements = new Array();
for (var i = 0; i < children.length; i++) {
var child = children[i];
var classNames = child.className.split(' ');
for (var j = 0; j < classNames.length; j++) {
if (classNames[j] == className) {
elements.push(child);
break;
}
}
}
return elements;
};
}
沒有留言:
張貼留言