I want to achieve following html
<li class="default_filter"><input type="checkbox" name="someName"/></li>
I tried:
var dome= "$('.ulContainer')";
var li= $('<li/>').text(data[i]).appendTo(dom);
var cbx=$('<input type='checkbox'/>').name("someName").appendTo(li);
尝试这个 :
$('.ulContainer').append('<li class="default_filter">' + data[i] + '<input type="checkbox" name="someName"/></li>');
If Javascript can do you can use below:
//loop starts here
var li = document.createElement('li');
li.className = 'default_filter';
var inputCB = document.createElement('input');
inputCB.type = 'checkbox';
inputCB.setAttribute('name','someName');
li.appendChild(inputCB);
$('.ulContainer').append(li);
//loop ends here.
You can use it in a loop to Make multiple li's
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.