正如标题所指的那样,这个函数似乎不适用于添加在 document.ready 函数之后的 DOM 元素。
我添加了一个新.window
元素,但这个函数仍然只处理.window
加载脚本时创建的元素。
我如何使它也对附加元素做出反应?
$(function() {
// Change this selector to find whatever your 'boxes' are
var windows = $("div.window");
// Set up click handlers for each box
windows.mousedown(function() {
var tz = parseInt($('#toolbar').css( "z-index" ), 10 );
$('#toolbar').css( "z-index", tz +1 )
var el = $(this), // The box that was clicked
max = 0;
// Find the highest z-index
windows.each(function() {
// Find the current z-index value
var z = parseInt( $( this ).css( "z-index" ), 10 );
// Keep either the current max, or the current z-index, whichever is higher
max = Math.max( max, z );
});
// Set the box that was clicked to the highest z-index plus one
el.css("z-index", max + 1 );
orderWindows(el);
});
});