开发者

$("input:checked").length not working in opera after go back in browser history

I have JavaScript witch contain this code:

$("input:checked").length 

After go back button clicked in browser this code $("input:checked").length; not working in opera. Is there anything i can do?

Basically I need to check if there was two radio-buttons checked or not

        <script>
    $(document).ready(function () {

        $("#signup").button();

        $("#signup").click(function () {

            alert($("#bb input:checked").length);
            if ($("#bb input:checked").length == 2) {
                $("#signup").val("1");                
            }
        });
    });
</script>

@using (Html.BeginForm())
{

<div id="wrapper">

    <div id="bb"> 
       <div id="rbl1" class="rbl1">
           <input type="radio" id="rb11" name="radio-b1" value="1"/><label for="rb11" class="radio">Everyday</label>
           <input type=开发者_如何转开发"radio" id="rb12" name="radio-b1" value="2"/><label for="rb12" class="radio">Saturday</label>
        </div>        

        <div id="rbl2" class="rbl2">
           <input type="radio" id="rb21" name="radio-b2" value="1"/><label for="rb21" class="radio">One</label>
           <input type="radio" id="rb22" name="radio-b2" value="2"/><label for="rb22" class="radio">Two</label>
        </div>
    </div>

</div>

<button name="submit" id="signup">Sugn up</button>
}

First time it is working well in all browsers, after radio buttons checked i submitting my form in that time everything fine. But then i just checked whats happened if i go back in browser history and submit form again, so all browsers fine except opera, it is failing on this code line $("#bb input:checked").length == 2) and didn't give any details why.

Before i used jQuery 1.5.1 now i updated to 1.5.2 and still the same problem. Detailed sample code updated, full html code posted here http://sourcepod.com/puvmmz30-4571

Probably something with Opera history going wrong.

Is there somehow else i may set value of $("#signup").val("1"); or check if radio list selected ("#bb input:checked") and Opera history didn't clear that.


Have you tried to use size() rather than length?


I can reproduce this problem using Opera 12.12 and jQuery 1.6.1. I cannot reproduce this if I upgrade jQuery to 1.9.1.

If you can't upgrade your jQuery version, you can get the correct checked value using .each() and value.checked.

See: $(".reasons input").each(function(index, value) {console.log(value.checked, value)})

It returns the correct values for checked.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜