使用jQuery将复选框添加到无序列表

Raú*_*Roa 2 html javascript jquery

什么是jQuery代码<li>,为无序列表中的每个元素添加一个复选框,并处理它们的回调获取li文本或复选框属性,如名称/值?

我从这样的事情开始:

$(document).ready(function() {
   $("#SuperTextbox1_Results").children('li').each(function() {
      $(this).prepend('<input type="checkbox" name="test" value="test" />');
   });
});
Run Code Online (Sandbox Code Playgroud)

RaY*_*ell 6

// checkbox click event handler
$('input:checkbox.liChk').live('click', function () {
    // access parent li, do whatever you want with it
    console.log($(this).parent('li'));
});    

// append checkboxes to all li tags
$('<input type="checkbox" class="liChk" />').appendTo('li');
Run Code Online (Sandbox Code Playgroud)