Thursday 15 January 2015

jquery - Linked radio buttonsets not updating on second press -


I have participated in a problem and I do not know how to solve it (and yes, I have no search function Used correct result). Hope can be found in a simple example that you can help.

There are several buttons in my setup that contain radio buttons when users press a value on a button, other buttons should be updated to show the option made by the user.

My problem is that for the first time the buttons that are clicked on the radio button by the user are updated (either by pressing 1 on the buttonset in JSFDell or another), but after changing the option, on the same element The second click does not update it anymore (in JSFDell example, clicking on 1 -> click -> -> 1 will show problem) I have used the Google Chrome Developer function and found that as soon as One element is updated, even then I have checked the status of fresh (either the button or buttonset), checked = "check". I tried to keep track of the previous clicked radiobutan and trying to lie to them (commented in jsFiddle example) It takes the property, but then no views are updated.

So how does this have any ideas on how to solve it? The library used is just a jQuery

HTML:

  & lt; Div id = "two_buttonsets" & gt; & Lt; Div id = "test1" & gt; & Lt; Input type = "radio" id = "component_0_test_0" name = "component_test_0" value = "0" check = "check" /> & Lt; Label = "component_0_test_0" & gt; 0 & lt; / Labels & gt; & Lt; Input type = "radio" id = "component_1_test_0" name = "component_stest" "value =" 1 "/> 
label =" component_1_test_0 "> 1 & Lt; Label = "component_2_test_0" & gt; 2 & lt; / Labels & gt; & Lt; / Div & gt; & Lt; Div id = "test2" & gt; & Lt; Input type = "radio" id = "component_0_test_1" name = "component_test_1" value = "0" check = "check" /> & Lt; Label = "component_0_test_1" & gt; 0 & lt; / Label & gt; For & lt; Input type = "radio" id = "component_1_test_1" name = "component_test_1" value = "1" /> & Lt; Label = "component_1_test_1" & gt; 1 & lt; / Labels & gt; & Lt; Input type = "radio" id = "component_2_test_1" name = "component_test_1" value = "2" /> & Lt; Label = "component_2_test_1" & gt; 2 & lt; / Labels & gt; & Lt; / Div & gt; JS / jQuery:
  jQuery (function () {$ ('# test1'). Buttonset (); $ ('# test2') .bootset (); / * var previous_clicked = [ ]; $ ('#two_buttonsets div [id * = "test"] input: checked') .each (function () {previous_clicked.push ($ (this) .attr ('id'))}}; Click on a component button. $ ('Div [id * = "test"] input'). Click (function () {// previous clicked values ​​are checked = false / * $ ('' Previous ''); $ ('previous'; last ++) {$ ('#' + previous_quote [last]) .attr ('checked', false); $ ('#' + previous_quote [last ]). Button ('Refresh');} previous_clicked = []; * / // all Set the buttons in the same value var button_ id = $ (this) .attr ('id'); var to = button_id.lastIndexOf ('_', button_id.lastIndexOf ('_') - 1) + 1; var track_number = Button_id.substring (0, from); // Change all check buttons $ ('div [id * = "test"] input [id * = "' + track_number + '"]'). Each (function () {$ (This) .attr ('checked', true); // $ (this). Button ('Refresh'); // also does not work / / preverse_clicked.push ($) (this) .attr ('I'))); }) $ ('# Test1'). Buttonat ('refresh'); . $ ('# Test2') buttonset ('refresh'); }}}   

After being annoyed with it and surfing the Internet, I found out that What was the problem was that instead of using .attr was supposed to use .prop instead of me .attr and .prop should spend some time reading about the difference.

No comments:

Post a Comment