1

我是 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;
        }

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

4

1 回答 1

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');
}

最后,为了确保您不会被此困住,HTML 元素的 ID 由 ASP.net 更改,您添加了一个“runat="server"',因此如果您的 iframe 的 ID 为“IframeChart1”并且'runat' 属性然后 ASP 将把它变成类似 'iframe_01_h1' 的东西。您可以使用如下 ASP 代码获取此值:

document.getElementById('<%= IframeChart1.ClientID %>')
于 2013-02-25T07:48:23.310 回答