gpt4 book ai didi

jquery - 监听 DIV 内的变化并采取相应的行动

转载 作者:行者123 更新时间:2023-12-03 21:27:55 30 4
gpt4 key购买 nike

我有一个函数可以获取 XML 文档并根据 XSL 文档对其进行转换。然后,它将结果放入 id 为 laneconfigdisplay 的 div 中。我想要做的是,与转换逻辑分开,为该 div 设置一个 jQuery 更改事件,以便我可以知道它何时发生更改,并运行一些 jQuery 代码。

我已经尝试了以下方法,但不起作用!

$(document).ready(function()
{
$('#laneconfigdisplay').change(function() {
alert('woo');
});
//Do XML / XSL transformation here
});

<!-- HTML code here -->
<div id="laneconfigdisplay"></div>

我做错了什么?

最佳答案

您可以选择创建自己的自定义事件,这样您仍然可以清晰地分离逻辑。

绑定(bind)到自定义事件:

$('#laneconfigdisplay').bind('contentchanged', function() {
// do something after the div content has changed
alert('woo');
});

在更新 div 的函数中:

// all logic for grabbing xml and updating the div here ..
// and then send a message/event that we have updated the div
$('#laneconfigdisplay').trigger('contentchanged'); // this will call the function above

关于jquery - 监听 DIV 内的变化并采取相应的行动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2712124/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com