使用Jquery检查是否存在通过局部视图加载的元素

扎克

我正在一个ASP.net mvc项目上,并使用部分视图加载一些html。我想检查info-cache元素一旦加载到主页后是否可用,但是我的脚本似乎无法正常工作。我绝对可以看到部分视图内容已加载到页面上,但是脚本似乎没有触发,因为我看不到“已加载”消息写入控制台。知道我哪里出错了吗?非常感谢。

<!-- partial view content -->
<div class="info-display">
   <input class="info-cache" type="hidden">
   <a href="#" class="info-update">Update</a>
</div>

//Script
$('body').on('load', '.info-cache', function () {
   console.log('loaded');
});
法国式

如果您想捕获是否有东西退出,可以使用setInterval重复操作

var timer = setInterval(function () {
  if ($("input.info-cache").length) {
    clearInterval(timer);
    console.log('loaded');
  }
}, 250);//you could adjust the lapse for the next repeat

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章