开发者

jQuery/Javascript problem with IE

I have two radio buttons each with a unique ID. When one is clicke开发者_StackOverflow中文版d, I would like to add $10 to a total. When the other is clicked, we go back to the original total price. My jquery looks like this:

function check_ceu() {
    var price = <%= conference_price %>;
    if($('#ceu_yes').is(':checked')){
            $('#total').val(parseFloat(price) + 10)
        }
        else{
            $('#total').val(price)
        }       
}

I have this function bound to document.ready (for page refreshes) and also the onchange handler of the radio buttons.

In FF and Chrome this works fine. In IE, when the radio button with ID of "ceu_yes" is checked nothing happens, then when clicking back to the other radio button, 10 is added. So in essence, IE has the checkbox functionality reversed. Below is my code for the buttons:

<input type="radio" name="ceu" id="ceu_yes" value="1" onchange="check_ceu()" /> $10
<input type="radio" name="ceu" id="ceu_no" value="0" checked="checked" onchange="check_ceu()" /> No, thank you

Any ideas on this?


IE's 'change' event handler is messed up. It doesn't fire when expected. (http://webbugtrack.blogspot.com/2007/11/bug-193-onchange-does-not-fire-properly.html)

If you change your logic to attach to the 'click' event on your radio button, you will get the effect that you want.

NB. Nicely enough, the click event still fires properly when you tab into the field and manipulate it using the spacebar on the keyboard, so no functionality is lost.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜