[英]IFrame : Page is post back or refreshing on iframe src
我是asp.net的新手。 我正在調用Iframe src拋出表行javscripct click事件。 (即onclick =“ return loadPhaseWiseChart(” DGSET00025“);”)
我的代碼:-
<tr height="25" id="row3" onclick="return loadPhaseWiseChart("DGSET00025");" bgColor="#e1f2fe">
<td>
<tr>
jQuery代碼:-
function loadPhaseWiseChart(Asset_Discription) {
document.getElementById('IframeChart1').src = "PhaseOneChart.aspx?assetdiscription=" + Asset_Discription;
}
當我單擊行時,我的頁面正在回發或刷新。 我想避免頁面刷新或回傳行單擊事件。 我該怎么做。 任何幫助將不勝感激。
您的onClick應該看起來像這樣:
<tr height="25" id="row3" onclick="loadPhaseWiseChart('DGSET00025');" bgColor="#e1f2fe">
請注意返回值的刪除以及內部字符串和外部屬性使用不同的引號類型(在JavaScript中,這些類型可以互換,但它們至少必須匹配。實際上,使用jQuery時,您不應添加這樣的onClick根本不用像這樣使用數據屬性:
<tr height="25" id="row3" data-chart="DGSET00025" bgColor="#e1f2fe">
並將您的函數綁定到click事件,如下所示:
$('#row3').on('click', loadPhaseWiseChart);
這會將您的“ loadPhaseWiseChart”更改為:
function loadPhaseWiseChart() {
document.getElementById('IframeChart1').src = "PhaseOneChart.aspx?assetdiscription=" + $(this).data('chart');
}
最后,只是確保您不會被此陷阱所困,ASP.net會通過添加“ runat =“ server””來更改HTML元素的ID,因此,如果您的iframe的ID為“ IframeChart1”,並且該“運行”屬性,然后ASP會將其轉換為類似“ iframe_01_h1”的內容。 您可以通過以下一些ASP代碼獲得此值:
document.getElementById('<%= IframeChart1.ClientID %>')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.