2011-05-10 92 views

回答

17
$('#containerId').append('<input type="checkbox" name="myCheckbox" />'); 

其中containerId是您要添加複選框的DOM元素的ID。

或者替代語法...

$('#containerId') 
    .append(
     $(document.createElement('input')).attr({ 
      id: 'myCheckbox' 
      ,name: 'myCheckbox' 
      ,value: 'myValue' 
      ,type: 'checkbox' 
     }) 
    ); 
+1

第二段代碼中的逗號放置非常殘酷。 – NorCalKnockOut 2017-08-29 20:30:09