最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

html - Anchor Tag with onclickJavaScript attribute. Stop refreshing page in I.E - Stack Overflow

matteradmin1PV0评论

I have a HTML/JavaScript project that holds a few dozen anchor tags; each of the anchor tags calls the same JavaScript function, but with a different parameter.

Everything looks good in Firefox and Chrome, but in Internet Explorer (IE) the page seems to reload (flicker) every time I click an anchor tag (like the one shown below). How can I make IE stop reloading/flickering? I would prefer not to rewrite the whole script. I have tried onclcick='javascript... and href='javascript...,but both have the same problem (although onclick seems a little better).

<a onclick='javascript:foo(22)'></a> 

I have a HTML/JavaScript project that holds a few dozen anchor tags; each of the anchor tags calls the same JavaScript function, but with a different parameter.

Everything looks good in Firefox and Chrome, but in Internet Explorer (IE) the page seems to reload (flicker) every time I click an anchor tag (like the one shown below). How can I make IE stop reloading/flickering? I would prefer not to rewrite the whole script. I have tried onclcick='javascript... and href='javascript...,but both have the same problem (although onclick seems a little better).

<a onclick='javascript:foo(22)'></a> 
Share Improve this question edited Jun 10, 2012 at 19:07 TazGPL 3,7482 gold badges40 silver badges60 bronze badges asked May 26, 2011 at 4:24 John RJohn R 3,03613 gold badges51 silver badges62 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 10

Try <a onclick='foo(22); return false;'></a>

Also, javascript: is pointless in event attributes as it just defines a label.

Simpler to use jQuery:

<a href="#" class="action" rel="22"></a>
<script>
    $('.action').click(function(){
        yourfunction($(this).attr('rel');
        return false;
    });
</script>
Post a comment

comment list (0)

  1. No comments so far