简体   繁体   English

使用load()加载还使用jQuery的页面

[英]using load() to load page that also uses jQuery

I'm trying to load a page that is basically an edit form inside a dialog (ui.dialog). 我正在尝试加载一个基本上是对话框(ui.dialog)内的编辑表单的页面。 I can load this page fine from an external (I'm using asp.net) page. 我可以从外部(我正在使用asp.net)页面加载此页面。

The problem is that inside of my "popup" form, I need to $(function() {my function here}); 问题是在我的“弹出”表单中,我需要$(function() {my function here}); syntax to do some stuff when the page loads, along with registering some .fn extensions for some dynamic dropdowns using ajax calls. 语法可在页面加载时执行一些操作,并使用ajax调用为某些动态下拉菜单注册一些.fn扩展名。

I have created my <script type="text/javascript" src="jquery.js"> but I don't think these are being included, and also my $(function) is not being called. 我已经创建了我的<script type="text/javascript" src="jquery.js">但是我不认为这些被包括在内,而且我的$(function)也没有被调用。

Is this possible to do or do I need to find another way of accomplishing what I need to do? 这是可能做的事情还是我需要找到另一种方法来完成我需要做的事情?

If you really need to load that form via AJAX you could to do all the Javascript stuff in $.ajax callback itself. 如果您确实需要通过AJAX加载该表单,则可以在$ .ajax回调本身中完成所有Javascript内容。 So, you load the popup form like this: 因此,您将加载弹出表单,如下所示:

$.ajax({
   //...
   success: function(text) {
       // insert text into container
       // the code from $(function() {});
   }
});

The script isn't getting run because the document's ready event has already been fired. 该脚本无法运行,因为文档的ready事件已经被触发。 Remove your code from within the 从以下位置删除您的代码

$()

Use the livequery plugin. 使用livequery插件。

It allows you to bind events to elements that might be loaded later: http://brandonaaron.net/docs/livequery/ 它允许您将事件绑定到以后可能加载的元素: http : //brandonaaron.net/docs/livequery/

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

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