jQuery --- realization checkbox style checkbox

This is written before a modal radio frame required but requires a hard to read default style radio checkbox + js wanted to use their turning it into a single box the following:

  html code:

Copy the code
<div class="list-item">
    <input type="checkbox" id="1" value="">
    <label for="1">Dance of the Reed Pipes</label>
</div>
<div class="list-item">
    <input type="checkbox" id="2" value="">
    <label for="2">Dance of the Reed Pies</label>
</div>
<div class="list-item">
    <input type="checkbox" id="3" value="">
    <label for="3">Dance of the Reed Pipes</label>
</div>
<div class="list-item">
    <input type="checkbox" id="4" value="">
    <label for="4">Dance of the Reed Pipes</label>
</div>
<div class="list-item">
    <input type="checkbox" id="5" value="">
    <label for="5">Dance of the Reed Pipes</label>
</div>
Copy the code

  js code:

Copy the code
. $ (. "List-Item") the Click (function () { 
     . $ (. "List-Item") Find ( "INPUT [type = 'CheckBox']") prop ( "the checked", to false);. / / before each click, all unchecked checkbox set 
     var cobj = $ (this) .find ( "input [type = 'checkbox']"); // current click checkbox 
     cobj.prop ( "the checked", to true ); // set the current click checkbox is checked 
        // over 
})
Copy the code

  The code is not complicated very simple, if you want to get id of clicks, just add a 

var itemId = cobj.attr("id");

  that's it 

Guess you like

Origin www.cnblogs.com/amylis_chen/p/11520560.html