【问题标题】:IFrame : Page is post back or refreshing on iframe srcIFrame:页面在 iframe src 上回发或刷新
【发布时间】:2013-02-10 07:35:40
【问题描述】:

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

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

【问题讨论】:

    标签: c# javascript jquery asp.net iframe


    【解决方案1】:

    您的 onClick 应如下所示:

    <tr height="25" id="row3" onclick="loadPhaseWiseChart('DGSET00025');" bgColor="#e1f2fe">
    

    注意返回的删除,以及对内部字符串和外部属性使用不同的引号类型(在 JavaScript 中,这些类型是可以互换的,但它们必须至少匹配。实际上,使用 jQuery 你不应该添加onClick 完全像这样,而是使用这样的数据属性:

    <tr height="25" id="row3" data-chart="DGSET00025" bgColor="#e1f2fe">
    

    并将您的函数绑定到点击事件,如下所示:

    $('#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 %>')
    

    【讨论】:

      猜你喜欢
      • 2011-11-15
      • 2016-11-10
      • 2012-06-18
      • 1970-01-01
      • 2018-02-27
      • 1970-01-01
      • 2018-02-23
      • 2013-05-21
      • 1970-01-01
      相关资源
      最近更新 更多