【问题标题】:NyroModal Not Working On Added Links with jQueryNyroModal 无法使用 jQuery 添加链接
【发布时间】:2011-08-11 16:42:16
【问题描述】:

我有这个 NyroModal:

$('.openModal').nyroModal();

然后我有我的链接:

<a href="#sample" class="openModal">this is a test</a>

这很好用,它会按预期加载我的示例模式,但是当我使用

添加链接时
$("#mydiv").html('<a href="#sample" class="openModal">this is a test</a>');

不行,我试过了

$('.openModal a').live('click',function(e) {
        e.preventDefault();
        $(this).nyroModalManual();
        return false;
});

还有这个:

$('.openModal a').live('click',function(e) {
        e.preventDefault();
        $(this).nmManual("#sample");
        return false;
    });

但我没有任何运气,你能想出其他我可以尝试的方法吗?我做错了什么?

谢谢!

更新:我忘了说我的控制台没有任何错误

更新 2:我现在收到此错误,现在我选择正确:

Uncaught TypeError: Object [object Object] has no method 'nyroModalManual'

【问题讨论】:

    标签: javascript jquery nyromodal jquery-click-event


    【解决方案1】:

    他呢?

    $('.openModal a').live('click',function(e) {
            e.preventDefault();
            $.nmManual("#sample");
        });
    

    或者我猜你有这个选择器:

    $('a.openModal').live('click',function(e) {
            e.preventDefault();
            $.nmManual("#sample");
        });
    

    【讨论】:

      【解决方案2】:

      看起来你想要 a.openModal 作为你的选择器。目前它在类 openModal 中选择一个元素。 您可能想改用委托,现在首选 iirc。

      我看到了你的更新。你不应该用 nyroModal 来调用它,而不是 nyroModalManual 吗? nmManual 看起来也可能有效。

      【讨论】:

      • 您好corn_dog,感谢您的回复,我已经尝试过了,确实似乎我没有正确选择元素。但是,我现在遇到了一个错误,我用它所说的内容更新了我的问题。再次感谢
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-25
      • 2012-08-13
      • 2012-01-23
      • 1970-01-01
      • 2018-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多