Я пытаюсь вставить этот скрипт внутри вкладки начальной загрузки. Моя цель - построить таблицу динамически.bootstrap: динамически вставлять строку во вкладку
Моя проблема, каждый раз, когда я вставляю новую строку, моя страница обновляется.
У вас есть вопросы по устранению проблемы?
<table class="table table-sm table-hover" id="mtable">
<thead>
<tr>
<td>Item</td>
<td>Red</td>
<td>Green</td>
</tr>
</thead>
<tbody>
<tr>
<td>Some Item</td>
<td><input type="checkbox" /></td>
<td><input type="checkbox" /></td>
</tr>
</tbody>
</table><br /><br />
<input id="row" placeholder="Enter Item Name" />
<button id="irow">Insert Row</button><br /><br />
<input id="col" placeholder="Enter Heading" />
<button id="icol">Insert Column</button>
<script>
$('#irow').click(function(){
if($('#row').val()){
$('#mtable tbody').append($("#mtable tbody tr:last").clone());
$('#mtable tbody tr:last :checkbox').attr('checked',false);
$('#mtable tbody tr:last td:first').html($('#row').val());
}else{alert('Enter Text');}
});
$('#icol').click(function(){
if($('#col').val()){
$('#mtable tr').append($("<td>"));
$('#mtable thead tr>td:last').html($('#col').val());
$('#mtable tbody tr').each(function(){$(this).children('td:last').append($('<input type="checkbox">'))});
}else{alert('Enter Text');}
});
</script>