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

javascript - prevent radio button to be checked when clicked - Stack Overflow

programmeradmin0浏览0评论

I need to stop prevent default behavior of radio button to check if it checked before I click it or not, I'm using .live('click', function (){}) because the HTML added to DOM with AJAX

I need to stop prevent default behavior of radio button to check if it checked before I click it or not, I'm using .live('click', function (){}) because the HTML added to DOM with AJAX

Share Improve this question edited Jul 25, 2011 at 17:05 SLaks 888k181 gold badges1.9k silver badges2k bronze badges asked Jul 25, 2011 at 17:02 ZamblekZamblek 8091 gold badge14 silver badges22 bronze badges 4
  • 1 Afaik, it is not possible to prevent default behavior from within a live handler. By the time it is run, the event already bubbled up and the default behavior executed. – Šime Vidas Commented Jul 25, 2011 at 17:10
  • What default behavior specifically do you want to prevent? – Šime Vidas Commented Jul 25, 2011 at 17:31
  • You can disable the radio button and/or invert the checked property upon clicking. Ex: radio.checked = !radio.checked;. Afterwards, you can invert the checked property back if a certain criteria is met. – user1385191 Commented Jul 25, 2011 at 18:53
  • Possible duplicate of preventing a user from changing the state of a radio button – Jessica Commented Aug 18, 2016 at 2:35
Add a ment  | 

2 Answers 2

Reset to default 6

Just return false; from the handler.

Just return false

.live('click', function (){
        return false;
    }) 
发布评论

评论列表(0)

  1. 暂无评论