कैसे करने के लिए नया div टैग को जोड़ने के बॉक्स की जांच करने के लिए अगले जब चेक बॉक्स को चेक किया गया है और यह भी दो चेक बॉक्स को चेक किया दो div टैग प्रदर्शन होने के लिए करना चाहिए। कृपया मदद और मुझे jQuery का उपयोग कर इस मॉड्यूल का समाधान करने के लिए कर
नई div टैग को जोड़ने के लिए कैसे जब चेक बॉक्स jQuery का उपयोग कर चेक किया गया है
वोट
0
1 जवाब
वोट 2
2
$(':checkbox').click(function () {
if ($(this).attr('checked')) {
// create new div
var newDiv = $('<div>contents</div>');
// you can insert element like this:
newDiv.insertAfter($(this));
// or like that (choose syntax that you prefer):
$(this).after(newDiv);
} else {
// this will remove div next to current element if it's present
$(this).next().filter('div').remove();
}
});
आप चेकबॉक्स 'लेबल के बगल में इस नए div जोड़ने के लिए wan't तो पहले सुनिश्चित करें कि आप अपने चेक बॉक्स के लिए आईडी के सेट और लेबल में विशेषता के लिए कि उपयोग चेक बॉक्स के साथ लेबल कनेक्ट करने के लिए किया है:
<label for="myCb1">test</label>
<input type="checkbox" id="myCb1" value="1" />
अब आप बस थोड़ा ऊपर जे एस कोड को संशोधित कर सकते हैं और आप कर रहे हैं:
$(':checkbox').click(function () {
// current checkbox id
var id = $(this).attr('id');
// checkbox' label
var label = $('label[for=' + id + ']');
if ($(this).attr('checked')) {
// create new div
var newDiv = $('<div>contents</div>');
// insert div element
newDiv.insertAfter(label);
} else {
// this will remove div next to current element if it's present
label.next().filter('div').remove();
}
});













