简体   繁体   English

在第3方窗口中执行jQuery(原型)

[英]Execute jQuery in a 3rd party window (prototype)

This is my main question for ages and i never got a 100% answer (in some of the cases i managed to do what i want) and now i realize that i need a proper 100% answer to proceed. 这是我多年来的主要问题,我从来没有得到100%的答案(在某些情况下,我设法做到了自己想要的),现在我意识到我需要一个适当的100%的答案才能继续。

I'm running Prototype-UI (Draggable windows and stuff) and i need to know how can i run jQuery scripts inside of these windows while fetching the content with Ajax. 我正在运行Prototype-UI(可拖动的窗口和其他内容),我需要知道如何在使用Ajax获取内容的同时在这些窗口中运行jQuery脚本。

Here is an example of what worked out for me: 这是为我解决的一个示例:

             window.show_confirm = function(id) {
        var r = confirm("huhuhu");
        if (r == true) {
            jQuery.post('huhuhu.php', {'id':id}, function(data){});
              jQuery('#_'+id).animate({
        height: "0px",
        opacity: 0.0,
      }, 1500 );

        } else {
            alert("Item ["+id+"] was not deleted.");
        }

}

Here is an example of something that doesn't work: 这是不起作用的示例:

jQuery(function() {
jQuery(".line").peity("line");
});

Now the working example needs a click to run the function (this way users can only run it AFTER they opened the window). 现在,该工作示例需要单击以运行该功能(这样,用户只能在打开窗口后运行它)。

In the second case this function needs to run from the moment the document is ready (basically when its executed there is still no DOM with .line class.) 在第二种情况下,此功能需要从文档准备就绪时开始运行(基本上在执行文档时,仍然没有.line类的DOM)。

Any help? 有什么帮助吗?

I'm a little confused as to what you're asking, but from the last part I'm assuming it's how to call a jQuery function on is created that don't exist yet. 对于您要问的问题,我有些困惑,但是从最后一部分开始,我假设这是如何创建尚不存在的jQuery函数的。

jQuery is an imperative library, not a declarative one – as a rule it only operates on currently existing elements (with the exception of "live" event handlers but that's not your use case). jQuery是一个命令式库,而不是一个声明 库–通常它仅对当前存在的元素起作用(“实时”事件处理程序除外,但这不是您的用例)。 You need to make the call after the matching element is created somehow – either by doing the call after an AJAX request, or by using something like livequery to intercept DOM element creation. 您需要以某种方式创建匹配元素后进行调用-通过在AJAX请求之后进行调用,或使用诸如livequery之类的方法来拦截DOM元素的创建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM