[英]Running javascript function on data from .load(url)
Basically, I have a page with a "tabbed" div and when a user clicks on one of the tabs there is an .html page loaded into that div. 基本上,我有一个带有“选项卡式” div的页面,当用户单击其中一个选项卡时,该div中将加载一个.html页面。 I was wondering is there anyway that I can have a JS function ran on that new data that is loaded from the .load() javascript function.
无论如何,我想知道是否可以在从.load()javascript函数加载的新数据上运行JS函数。
Here's the function that loads the new data; 这是加载新数据的函数;
function switchAssetTabContent(tabContext, func, params) {
$("#ctl00_ContentPlaceHolder1_Overview1_tcAssetAllocation_tpAssetClassPrimary").html('<table width="375px" height="auto" style="min-height: 100px; height: auto; width: 260px;"><tr><td align="center" valign="middle"><img src="/backoffice/Prospects/App360/images/spinwait.gif" /></td></tr></table>');
var url = "pageFragments/overview/" + tabContext + ".html";
$("#ctl00_ContentPlaceHolder1_Overview1_tcAssetAllocation_tpAssetClassPrimary").load( url +"?" + (new Date().getTime()), params, updateYesterday );
}
the thing is that the data that is loaded is as follows; 问题是加载的数据如下;
<div bgcolor="white" id="ctl00_ContentPlaceHolder1_Overview1_pnlAssetClassAllocation">
<table cellspacing="0" cellpadding="0" style="width: 375px;" border="0">
<tr><td
valign="top"
style="background-color: white vertical-align: top; width: 175px"
id="ctl00_ContentPlaceHolder1_Overview1_tdAssetClassChart">
<div bgcolor="white" style="padding:0" id="AssetClassChartControlDiv" class="chart">
</div>
</td>
<td valign="top">
<div id="ctl00_ContentPlaceHolder1_Overview1_pnlAssetClassLegend">
<input type="hidden" value="" name="ctl00xContentPlaceHolder1xOverview1xuwgAssetClassChartLegend" id="ctl00_ContentPlaceHolder1_Overview1_uwgAssetClassChartLegend" />
<table cellspacing="0" cellpadding="0" border="0" style="overflow: hidden; position: relative;" id="ctl00xContentPlaceHolder1xOverview1xuwgAssetClassChartLegend_main">
<tr id="ctl00xContentPlaceHolder1xOverview1xuwgAssetClassChartLegend_mr">
<td align="left" style="vertical-align: top;">
<div id="AssetClassChartControl_legend" class="legend">
</div>
</td>
</tr>
</table>
</div>
</td></tr>
</table>
</div>
and i have js functions written on the main page that calls that info that uses the ID's of those now loaded html <div>
s and <span>
s. 我在主页上编写了js函数,该函数调用该信息,该信息使用了现在加载的html
<div>
和<span>
的ID。 Can i just put the .js functions on the included page? 我可以只将.js函数放到包含的页面上吗? I just thought i should only include my js functions in the
<head></head>
or outside of the <body></body>
tags..... any help is greatly appreciated. 我只是认为我应该只将我的js函数包含在
<head></head>
或<body></body>
标记之外.....非常感谢您的帮助。
If you want to re-run your document.ready()
function, you can make it a named function: 如果要重新运行
document.ready()
函数,可以将其命名为函数:
function myReadyFunction() { ... }
document.ready(myReadyFunction);
Then you can use it when calling .load()
: 然后,您可以在调用
.load()
时使用它:
$("#ctl00_ContentPlaceHolder1_Overview1_tcAssetAllocation_tpAssetClassPrimary").load( url +"?" + (new Date().getTime()), params, myReadyFunction );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.