它適用於預製div,但在新制作的div上不起作用。我如何解決這個問題?使用javascript更改zIndex
這裏有一個關於該事件的代碼改變用zIndex:
$(".widget").mousedown(function (event) {
var ws = document.getElementById("widget-workspace");
var list = ws.children, x=0;
for(x=0;x<ws.children.length;x++){
console.log(ws.children[x].id);
$("#"+ws.children[x].id).css("zIndex", 99);
}
$(this).css("zIndex", 100);
});
現在,這裏的代碼添加DIV:
document.getElementById("widget-dialog-button").onclick = function() {
var ws = document.getElementById("widget-workspace");
var list = ws.children;
var x, w = document.getElementById("select-widget");
var widget = w.options[w.selectedIndex].value;
var c = document.getElementById("select-widget-color");
var color = c.options[c.selectedIndex].value;
var left = 0, top = 25, docWidth = ws.offsetWidth, check;
for(x=0; x < list.length; x++){
docWidth -= 325;
left += 325;
if(docWidth < 325){
check = false;
docWidth = ws.offsetWidth;
left = 0;
top += 210;
}else{
check = true;
}
}
x-=2;
var iDiv = document.createElement('div');
iDiv.id = 'widget_'+x;
iDiv.className = 'widget';
iDiv.style.backgroundColor = color;
iDiv.style.left = left;
iDiv.style.top = top;
ws.appendChild(iDiv);
$(function() {
$(".widget").draggable();
});
};
如果你們有什麼需要,隨時問。
什麼可行,哪些不行?你的代碼有什麼問題?你想達到什麼目的? – orange 2014-12-08 02:27:43
使用Jquery'On'函數... – vijaykumar 2014-12-08 02:28:52