最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why does jQuery .click() not cause postback when used on this <a> tag? - Stack Overflow

programmeradmin1浏览0评论

Think this is a quickie for someone. I have this markup (generated by ASP.Net)...

<A id=anchorO href="javascript:__doPostBack('anchorO','')">O</A>

This anchor is in an update panel, and if I click it manually a partial postback takes place. However....

$('[ID$="anchor'+initial+'"]').click()   //JavaScript

..selects the correct anchor, but no postback takes place. Why is this?

Think this is a quickie for someone. I have this markup (generated by ASP.Net)...

<A id=anchorO href="javascript:__doPostBack('anchorO','')">O</A>

This anchor is in an update panel, and if I click it manually a partial postback takes place. However....

$('[ID$="anchor'+initial+'"]').click()   //JavaScript

..selects the correct anchor, but no postback takes place. Why is this?

Share Improve this question asked Apr 15, 2011 at 10:24 El RonnocoEl Ronnoco 11.9k5 gold badges40 silver badges67 bronze badges 1
  • stackoverflow./a/26560976/184572 – Iman Commented Oct 25, 2014 at 9:25
Add a ment  | 

2 Answers 2

Reset to default 6

A click and a href are seen as two different things in Javascript, so you can't do .click() and call the href, regardless if this is calling javascript: or not

Two options:

  1. Just do:

    $('#anchor' + initial).click(function() { __doPostBack('anchorO',''); });
    
  2. Be evil and use eval:

    $('#anchor' + initial).click(function() { eval($(this).attr('href')); });
    

See this question here

It appears that you can't follow the href of an a tag using the click event.

发布评论

评论列表(0)

  1. 暂无评论