我已经创建了一个自定义对话窗口类,并希望它代表一个DOM对象,以便jQuery能够在其上应用选择器。我想将对话实例与它创建的DOM元素相关联。我该怎么做才能使这段代码有效?
var instances_counter = 0
var dialogue = function()
{
this.id = ++instances_counter
$("body").append("<div id='dlg" + this.id + "'>[[[<div class='msg'>Message.</div>]]]</div>")
}
var dlg1 = new dialogue()
var dlg2 = new dialogue()
// What behaviour I want to implement:
$(".msg",dlg2).css("color","red")
alert(dlg2 instanceof dialogue) // This must alert 'true'.
// To do the same as:
// $("#dlg2 .msg").css("color","red")