jquery dialog box: 在对话框中获取对话框ID
jquery dialog box: Get the dialog box ID while inside the dialog box
我有一个允许用户打开多个对话框的软件。无需对我正在做的事情进行很长的解释,是否可以从对话框中提取对话框的 ID?因此,例如,我可能有一个名为 'dialog1' 的对话框,然后是另一个名为 'dialog5' 的对话框,如果我单击这些对话框中任何一个的 HTML 中的 link(不是单击在对话框按钮上),我需要知道它是 'dialog1' 还是 'dialog5'.
目前我看到两个选项:
1# 使用保存对话框 ID 的 GET 变量打开对话框,然后让 PHP 在我需要的地方回显其 ID(并以任何 ajax 形式重新发送该信息,然后让该页面 return 如果对话框刷新等数据)...
2# 让每个页面都有一个具有特定 id 的 HTML dom 元素,然后让 JavaScript 在加载时找到该元素,将其替换为 运行 domly generated element(这样不会和新对话框冲突),然后用运行domly generated element遍历DOM动态拉取身份证...
我尝试了这两种方法,似乎方法 2 更好,因为它需要更少的维护,但它是一个丑陋的解决方案(并且如果 DOM 更改会中断)。有更好的方法来完成这项工作吗?
将委托的点击事件绑定到外部包装器,其中所有对话框的所有对话框 ID exists.use 通用 class("common-class")。
<div class="outer-wrapper">
<div id="dialog-1" class="common-class" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
<div id="dialog-2" class="common-class" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
</div>
jQuery(".outer-wrapper").on("click",".common-class",function(){
var dialogclick = jQuery(this).attr("id");
})
我有一个允许用户打开多个对话框的软件。无需对我正在做的事情进行很长的解释,是否可以从对话框中提取对话框的 ID?因此,例如,我可能有一个名为 'dialog1' 的对话框,然后是另一个名为 'dialog5' 的对话框,如果我单击这些对话框中任何一个的 HTML 中的 link(不是单击在对话框按钮上),我需要知道它是 'dialog1' 还是 'dialog5'.
目前我看到两个选项: 1# 使用保存对话框 ID 的 GET 变量打开对话框,然后让 PHP 在我需要的地方回显其 ID(并以任何 ajax 形式重新发送该信息,然后让该页面 return 如果对话框刷新等数据)...
2# 让每个页面都有一个具有特定 id 的 HTML dom 元素,然后让 JavaScript 在加载时找到该元素,将其替换为 运行 domly generated element(这样不会和新对话框冲突),然后用运行domly generated element遍历DOM动态拉取身份证...
我尝试了这两种方法,似乎方法 2 更好,因为它需要更少的维护,但它是一个丑陋的解决方案(并且如果 DOM 更改会中断)。有更好的方法来完成这项工作吗?
将委托的点击事件绑定到外部包装器,其中所有对话框的所有对话框 ID exists.use 通用 class("common-class")。
<div class="outer-wrapper">
<div id="dialog-1" class="common-class" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
<div id="dialog-2" class="common-class" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
</div>
jQuery(".outer-wrapper").on("click",".common-class",function(){
var dialogclick = jQuery(this).attr("id");
})