2011年11月30日 星期三

IE中使用迴圈呼叫jquery

//$(function(){
var stemp = "";
for (j=1;j < i;j++){
stemp = ".checkother"+j.toString();
$(stemp).click(function(){
var x = $(this).parent().nextAll('textarea');
if ($(this).attr('checked') != 'checked')x.css('display', 'none');
else x.css('display', 'inline');
x.css({
width:'75px',
height:'100px'
});
});
}
//});

i是全域變數,計算新增了幾組元素
在動態新增元素 checkbox, textarea 後
為了使新增的 textarea 可以開合
所執行的一段 jQuery
在 IE 8 中只有 for 迴圈最後一次指定到的元素會有動作
爛透了!!!!
只好改寫元素,在新增時加上 onclick 事件
將上述 jQuery 另外改寫為副程式呼叫

沒有留言:

張貼留言