重新加载后,Jquery 定位器正在查找错误的页面
我有以下页面: 默认.aspx widgets/rss.aspx
在使用以下代码加载 default.aspx 时,rss.aspx 会动态加载到 div 中:
$.get('/Widgets/rss.aspx', { TabControlID : 385}, function(data) {
$('#drbox385').html(data);
});
这可以正常工作。
rss.aspx 内的代码:
<input type="submit" value="Save" />
<div id="RSSfeed<%=TabControlID %>">
<script type="text/javascript">
var gurl = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q=<%=MyUrl%>&num=<%=MyCount %>";
$.getJSON(gurl, function (data) {
var feeds = data.responseData.feed;
if (!feeds) {
$("#RSSfeed<%=TabControlID %>").append('There was an error loading this feed.');
}
else
{
for (var i = 0; i < feeds.entries.length; i++) {
var entry = feeds.entries[i];
var title = entry.title;
var link = entry.link;
var description = entry.contentSnippet;
var html = "<div class='stippel'><img height='10' width='10' src='/images/rss10.png' style='margin-right:2px;'><a target='_blank' href='" + link + "' class='feed_item_link' title='" + description + "'>" + title + "</a></div>";
// this line doesn't work after reload
$("#RSSfeed<%=TabControlID %>").append($(html));
// end of bug
}
}
})
</script>
当您单击“保存”按钮时,配置数据将发布到 default.aspx 上的不可见 iframe 中 iframe 生成以下代码以使用新配置重新加载小部件:
$(document).ready(function(){
var str;
str = "<div style='text-align:center'><img src='/images/loading.gif' width='32' heigth='32'/></div>";
$(parent.document).find('#drbox385').html(str);
$.get('/Widgets/rss.aspx', { TabControlID : 385}, function(data) {
$(parent.document).find('#drbox385').html(data);
});
});
数据被加载回页面,但 rss.aspx 中的这行代码不起作用:
$("#RSSfeed<%=TabControlID %>").append($(html));
Jquery 正在寻找 rss.aspx 内部的 ID #RSSfeed385 default.aspx
更改此行为的正确语法是什么?
I have the following pages:
default.aspx
widgets/rss.aspx
The rss.aspx gets dynamically loaded into a div upon loading default.aspx with this code:
$.get('/Widgets/rss.aspx', { TabControlID : 385}, function(data) {
$('#drbox385').html(data);
});
This works without a problem.
Code inside rss.aspx:
<input type="submit" value="Save" />
<div id="RSSfeed<%=TabControlID %>">
<script type="text/javascript">
var gurl = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q=<%=MyUrl%>&num=<%=MyCount %>";
$.getJSON(gurl, function (data) {
var feeds = data.responseData.feed;
if (!feeds) {
$("#RSSfeed<%=TabControlID %>").append('There was an error loading this feed.');
}
else
{
for (var i = 0; i < feeds.entries.length; i++) {
var entry = feeds.entries[i];
var title = entry.title;
var link = entry.link;
var description = entry.contentSnippet;
var html = "<div class='stippel'><img height='10' width='10' src='/images/rss10.png' style='margin-right:2px;'><a target='_blank' href='" + link + "' class='feed_item_link' title='" + description + "'>" + title + "</a></div>";
// this line doesn't work after reload
$("#RSSfeed<%=TabControlID %>").append($(html));
// end of bug
}
}
})
</script>
When you click on the Save button the configuration data is posted to an invisible iframe on default.aspx
The iframe generates the following code to reload the widget with the new configuration:
$(document).ready(function(){
var str;
str = "<div style='text-align:center'><img src='/images/loading.gif' width='32' heigth='32'/></div>";
$(parent.document).find('#drbox385').html(str);
$.get('/Widgets/rss.aspx', { TabControlID : 385}, function(data) {
$(parent.document).find('#drbox385').html(data);
});
});
The data is loaded back into the page but this line of code in rss.aspx doesn't work:
$("#RSSfeed<%=TabControlID %>").append($(html));
Jquery is looking for ID #RSSfeed385 inside of rss.aspx instead of default.aspx
What is the correct syntax to change this behaviour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样进行追加。
我还添加了
window.top.document
来告诉他们在顶部文档上搜索,而不是在 rss.aspxhttp://api.jquery.com/append/
通过在前面添加 $,您实际上会搜索元素来添加它们,只需删除它即可添加 html 变量中存在的代码。
Make the append like that.
I have also add the
window.top.document
to tell them to search on top document and not inside the rss.aspxhttp://api.jquery.com/append/
By adding the $ in front you actually search for elements to add them, just remove it to add the code exist inside the html variable.