IFrame:页面在iframe src上回发或刷新

时间:2013-02-25 07:44:03

标签: c# javascript jquery asp.net iframe

我是asp.net的新手。我正在调用iframe src throw table row 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;
        }

当我点击行时,我的页面正在回复或刷新。我想避免页面刷新或回复行点击事件。 我怎么能这样做任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

你的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会更改HTML元素的ID,并添加'runat =“server”',因此,如果您的iframe的ID为' IframeChart1'和'runat'属性然后ASP将把它变成'iframe_01_h1'之类的东西。您可以使用以下某些ASP代码获取此值:

document.getElementById('<%= IframeChart1.ClientID %>')
相关问题