[英]How to get data-id of a div inside of a jQuery dialog?
I have divs within multiple jQuery dialogs. 我在多个jQuery对话框中都有div。 I want to execute a function on opening the jQuery dialog.
我想在打开jQuery对话框时执行一个函数。 For that I need to acquire the div's data-id.
为此,我需要获取div的数据ID。 The divs are named dynamically.
div是动态命名的。 When I get the data-id, I need to execute the network+data-id.fit() function.
当我获得数据ID时,我需要执行network + data-id.fit()函数。
The dialog looks sth. 该对话框看起来很……。 like this:
像这样:
<div class = "ui-dialog-titlebar ..."></div>
<div class = "info ui-dialog-content ...">
<p>..</p>
<div data-id = "'identifier'">
<div class = "vis-network"></div>
</div>
</div>
The dialog options: 对话框选项:
$( ".info" ).dialog({
autoOpen: false,
open: function() {
var networkDataId = $(this).data('id');
console.log(networkDataId);
network.fit();
},
height: 600,
width: 1000
});
You can use the jQuery .find()
function on your .info
selector to detect which element has a data-id
attribute : $('.info').find('[data-id]').data('id');
您可以在
.info
选择器上使用jQuery .find()
函数来检测哪个元素具有data-id
属性: $('.info').find('[data-id]').data('id');
$( ".info" ).dialog({
autoOpen: false,
open: function() {
var networkDataId = $('.info').find('[data-id]').data('id');
console.log(networkDataId);
network.fit();
},
height: 600,
width: 1000
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.