我想用jQuery實現簡單的pub/sub模式。 所以我添加一些代碼這樣的父頁:
父頁面:
$(document).bind('custom', function() { ... });
,它的工作很好,當我觸發同一頁上是這樣的:
同一頁:
$(document).trigger('custom'); // Working.
但是,當我在彈出頁面上觸發它,它不工作。
彈出頁面:
opener.$(document).trigger('custom'); // Not working.
$(opener.document).trigger('custom'); // Not working.
如果我綁定事件<body>
元素,它的工作原理找到。
父頁:
$('body').bind('custom', function() { ... });
彈出頁:
opener.$('body').trigger('custom'); // Working.
爲什麼結合document
不工作的彈出?
我認爲,因爲如果你從父頁面使用父頁面的'document'變量。 (opener.document).trigger('custom');'? – 11684