具有动态内容的jQuery对话框

我想即时创建一个jQuery对话框。我使用这个:
var newDiv = $(document.createElement('div')); 
$(newDiv).html('hello there');
$(newDiv).dialog();

然后我在html标题中有这个:

<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.1.custom.min.js"></script>

当我尝试在IE7中运行JS时,我在$(newDiv).dialog()上得到以下错误;行:
对象不支持属性方法

任何人都知道发生了什么事

解决方法

您的代码可以工作,您可以测试它 here,这意味着您可能有一个脚本包含问题,请确保您的文件位于页面旁边的js文件夹下,或者如果您希望它们来自站点根目录,请改用/ js。

或者,consider using a CDN

你可以使你的代码更有效率(我意识到这只是一个测试),像这样:

var newDiv = $(document.createElement('div')); 
newDiv.html('hello there');
newDiv.dialog();

这是因为newDiv已经是一个jQuery元素,没有理由克隆对象每次…或者更短一点:

$('<div />').html('hello there').dialog();

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...