我無法發現爲什麼瀏覽器掛起並被第一個for循環在這個函數中捕獲,arguments.length也不會打印console.log。爲什麼瀏覽器卡在這個JavaScript循環中?
這是通過在ColorPicker自己的ID則變量其他屬性點擊功能改變:
$('#colorSelector3').click(function(){
colorPickDynamic('#colorSelector3','h1','color');
});
這裏就是瀏覽器的第一個掛起循環功能:
function colorPickDynamic(cp){
var i,
j,
x,
tag = [],
colorProperty = [];
for (x=0, i = 1, j = 2; x <= arguments.length; i+=2, j+=2, x++) {
tag[x]=arguments[i];
colorProperty[x]=arguments[j];
console.log(arguments.length);
console.log(colorProperty[x]);
}
$(cp).ColorPicker({
color: '#0000ff',
onShow: function (colpkr) {
$(colpkr).fadeIn(500);
return false;
},
onHide: function (colpkr) {
$(colpkr).fadeOut(500);
return false;
},
onChange: function (hsb, hex, rgb) {
for (j = 2; j < arguments.length; j+=1) {
$(tag[0]).css(colorProperty[0], '#' + hex);
}
$(cp + ' div').css('backgroundColor', '#' + hex);
}
});
}
任何幫助將是驚人的!謝謝
在jsfiddle.net上顯示演示plz – IProblemFactory
在「循環」消失之前,您可以從中刪除多少代碼? – Deestan
您可能希望在腳本調試器中的第一個循環「body」中放置一個斷點,以便您可以看到「正在發生的內部」是什麼...... – benqus