$ ("input: checked"). Length does not work in opera after returning to browser history

I have JavaScript that contains this code:

$("input:checked").length 

After returning, click the button in the browser, this code is $ ("input: checked"). length; does not work in opera. Is there anything I can do?

Basically I need to check if two radio buttons were 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> } 

The first time it works well in all browsers, after the radio buttons have verified that I submit my form at this time, everything is fine. But then I just checked what happened if I go back to the browser history and submit the form again, so that all browsers are fine except opera, it fails on this $ ("# bb input: checked") code line. Length == 2) and did not give any details.

Before I used jQuery 1.5.1, now I upgraded to 1.5.2 and still the same question. Detailed example code updated, full html code sent here http://sourcepod.com/puvmmz30-4571

Perhaps there is something wrong with the history of Opera.

Somehow I can set the value of $ ("# signup"). val ("1"); or check if the list of radio stations ("#bb input: checked") is selected, and the Opera story did not understand this.

+4
source share
2 answers

Have you tried using size() rather than length ?

0
source

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 cannot upgrade the jQuery version, you can get the correct checked value using .each () and value.checked.

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

It returns the correct values ​​for the marked ones.

0
source

Source: https://habr.com/ru/post/1346415/


All Articles