最新消息: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)

javascript - How to make onclick event occur before onblur? - Stack Overflow

matteradmin9PV0评论

I have 2 elements, an anchor with onclick = "..." and an input with onfocus = "..." The anchor is toggled by the input button, so when the button is in focus, the anchor is displayed and when it loses focus the anchor is hidden. Is there a way I can access the onclick event from the anchor without the onblur occurring first?

input(type="radio", name="sample", value=str(sample['id']),
     id="S"+str(sample['id']),onfocus = 'javascript:toggleVisibility("%stoggle");' 
     % sample['id'], onblur = 'toggleVisibility("%stoggle");' % sample['id'])

a("edit", id = "%stoggle" % str(sample['id']), style="display:none; float:right;
   padding-left:10px; text-decoration:none;", href='do something')

I have 2 elements, an anchor with onclick = "..." and an input with onfocus = "..." The anchor is toggled by the input button, so when the button is in focus, the anchor is displayed and when it loses focus the anchor is hidden. Is there a way I can access the onclick event from the anchor without the onblur occurring first?

input(type="radio", name="sample", value=str(sample['id']),
     id="S"+str(sample['id']),onfocus = 'javascript:toggleVisibility("%stoggle");' 
     % sample['id'], onblur = 'toggleVisibility("%stoggle");' % sample['id'])

a("edit", id = "%stoggle" % str(sample['id']), style="display:none; float:right;
   padding-left:10px; text-decoration:none;", href='do something')
Share Improve this question asked Jul 10, 2012 at 7:20 atfergusatfergus 3204 silver badges18 bronze badges 3
  • What do you mean by access? You want to fire onClick event or just get the function? And what do you need it for? There might me better solution... – Gatekeeper Commented Jul 10, 2012 at 7:25
  • I'd just like to be able to change the value displayed with the radio button. As it is now, the href address or code won't execute because the onblur happens before the href fires. Is there a quick way I can just get that to happen? – atfergus Commented Jul 10, 2012 at 7:28
  • Does it work now or still facing issues? – WolvDev Commented Jul 11, 2012 at 8:05
Add a ment  | 

1 Answer 1

Reset to default 5

Try to use the onmousedown instead of onclick.

Post a comment

comment list (0)

  1. No comments so far