【问题标题】:img element srounded by an anchor is doing a post back被锚点包围的 img 元素正在回发
【发布时间】:2013-05-26 11:25:28
【问题描述】:

我知道一个“hack”,通过使 jquery 绑定单击事件跨越该包装来避免回发 img 元素 虽然这次我需要一个用于 seo 的 herf 这个对我不起作用,如果我用return false添加一个jquery代码,它就会被禁用 或者它会回帖。

<a id="a_ContactUs" href="contactUs.aspx">
    <span>
        <img class="img_ContatUs_CssClss" src="images/HebContactUs_RCL.png" alt="contact us" title="click here" />
    </span>
</a>

解决回发问题的正确方法是什么 并且仍然使用锚。

【问题讨论】:

  • 您是否注意到 a 标签中 a_ContactUs 后面缺少的 "?
  • @Silox 就在这里,谢谢,这不是真正的问题,因为我的代码没有语法错误
  • 你能发布你的相关 js/jquery 代码吗?我不确定是否理解您的问题。
  • @roasted 我明白了,伙计,感谢您的评论,我刚刚注意到...我确实有一个 return false 用于回帖,但没有采取行动重定向到 contact.aspx相同的功能,如果重要,我将发布我的完整代码(:问题已解决,再次感谢..

标签: jquery asp.net webforms postback


【解决方案1】:
$(' imgID or class here ').bind('click', function (e) {
    animatePageHide(e.target.id.split('_')[1] + ".aspx"); return false;
    // i have used the id as the page name... say contact.aspx the id of the element to bind
    // should be id="img_contact", then the split of the id returns the array that i take 
    // the array-element No1 which is 
   /*
   e.target.id[0] --> img
   e.target.id[1] --> contact
   then i concatenated the suffix ".aspx" thats it
   */
});

然后是在重定向时避免“打扰眼睛”页面刷新的功能:

function animatePageHide(pageURLRedirect2) {
    $("#DivNew_Main").fadeOut(500, function () {
         if (pageURLRedircet2 != undefined) window.location.href = pageURLRediret2 ;
    else window.location.href = "default.aspx";
    });

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-18
    • 1970-01-01
    • 2012-05-01
    • 2015-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多