gpt4 book ai didi

javascript - 如何使 tbody 子级大小与 thead 之后创建的第一个 tbody 大小相同

转载 作者:行者123 更新时间:2023-11-28 04:25:48 26 4
gpt4 key购买 nike

enter image description here

嗨,我有一个问题。我想问一下如何让tbody子元素的大小与thead后第一行的大小相同?

这是我的代码..请帮助我..您可以编辑我的 fiddle 或给出答案

    var theadFlag = 0;
var thdeadData = "";
$(document).on('click','#input_check',function(e){
e.preventDefault();

if(theadFlag == 0) { theadData ='<tr>'
+'<th>Nama Karyawan</th>'
+'<th>Tanggal</th>'
+'<th>Cost Center</th>'
+'<th>Jam Mulai</th>'
+'<th>Jam Selesai</th>'
+'<th>Status Lembur</th>'
+'<th>Total Jam</th>'
+'<th>Tugas</th>'
+'</tr>'
}
else
{
theadData = ""
}

var nama = $('input[id="nama_check"]').val(),
bagian = $('input[id="tanggal_check"]').val(),
cost = $('input[id="cost_check"]').val(),
mulai = $('input[id="start"]').val(),
selesai = $('input[id="end"]').val(),
status = $('input[id="status_check"]').val();
total = $('input[id="total_jam"]').val(),
tugas = $('input[id="tugas_check"]').val(),

$('tbody #body').append('<table id="check_data">'
+ theadData
+'<tr>'
+'<td>'+$("#nama_check").val()+'</td>'
+'<td>'+$("#tanggal_check").val()+'</td>'
+'<td>'+$("#cost_check").val()+'</td>'
+'<td>'+$("#start").val()+'</td>'
+'<td>'+$("#end").val()+'</td>'
+'<td>'+$("#status_check").val()+'</td>'
+'<td>'+$("#total_jam").val()+'</td>'
+'<td>'+$("#tugas_check").val()+'</td>'
+'</tr>'
+ '</table>');
theadFlag = 1;
});
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<!-- The Modal -->
<div id="myMd4" class="md4">
<!-- Modal content -->
<div class="md4-content" style="margin-top:20px">
<div id="data">

<table border="1" style="margin-left:50px">
<tr>
<td>
<table border="1">
<tr>
<td>
<form action="../php/absen/absen_karyawan_autocomplete.php" id="form_check" method="post" name="form_check">
<table>
<tr>
<td width="50" style="border-left:hidden; border-right:hidden"></td>
<td width="150">Nama Karyawan</td>
<td width="10">:</td>
<td width="150"><input type="text" id="nama_check" type="text" name="nama_check" size="25" style="float:left; text-transform:uppercase"> </td>
<td width="10" style="border-left:hidden; border-right:hidden"></td>
<td width="150">Tanggal</td>
<td width="10">:</td>
<td width="150"><input type="text" id="tanggal_check" type="text" name="tanggal_check" size="25" style="float:left; text-transform:uppercase"></td>
</tr>
<tr>
<td width="50" style="border-left:hidden; border-right:hidden"></td>
<td width="150">Jam Mulai</td>
<td width="10">:</td>
<td><input type="time" id="start" name="logintime" style="float:left"/></td>

<td width="100" style="border-left:hidden; border-right:hidden"></td>
<td width="150">Jam Selesai</td>
<td width="10">:</td>
<td width="150"><input type="time" id="end" name="logouttime" style="float:left"/></td>

</tr>
<tr>
<td width="50" style="border-left:hidden; border-right:hidden"></td>
<td width="150">Status Lembur</td>
<td width="10">:</td>
<td width="150"><select name="option2" id="option2" onchange="Choose1(this)" style="float:left">
<option value="-">-</option>
<option value="istirahat">istirahat</option>
<option value="tanpa istirahat">tanpa istirahat</option>
</select><input type="text" name="status_check" size="8" readonly="readonly" id="status_check" style="text-transform:uppercase" /></td>
<td width="10" style="border-left:hidden; border-right:hidden"></td>
<td width="150">Total Jam</td>
<td width="10">:</td>
<td width="150"><input type="text" id="total_jam" type="text" name="total_jam" size="25" style="float:left; text-transform:uppercase" ></td>
</tr>
<tr>
<td width="50" style="border-left:hidden; border-right:hidden"></td>
<td width="150">Cost Center</td>
<td width="10">:</td>
<td width="150"><input type="text" id="cost_check" type="text" name="cost_check" size="25" style="float:left; text-transform:uppercase" ></td>
<td width="10" style="border-left:hidden; border-right:hidden"></td>
<td width="150">Tugas</td>
<td width="10">:</td>
<td width="150"><input type="text" id="tugas_check" type="text" name="tugas_check" size="25" style="float:left" ></td>
</tr>
</table>
</form>
</td>
<td width="300">
<label class="button" name="input_check" id="input_check" style="height:35px; width:40px" />CLICK HERE</label>
<label class="button" name="edit_karyawan" id="edit_karyawan" style="height:35px; width:40px" />b</label>
<label class="button" name="delete_karyawan" id="delete_karyawan" style="height:35px; width:40px; " />c</label>
<label name="tutup" id="tutup" class="tutup" style="height:35px; width:40px;"/>d</label>
</td>
</tr>

</table>

</td>

</tr>
<tr>
<td>
<p align="center"><strong>Test</strong></p>
<table id="check_data" class="check_data" style="font-size:12px; margin-left:70px ">
<tbody id="body">
</tbody>
</table>
</td></tr></table>


</div>
</div>
</div>
<script>
function Choose1(data) {

document.getElementById ("status_check").value = data.value;

}
</script>

最佳答案

您有几个无效的 html 标签关闭。我认为正确的方法是附加 tr 而不是整个 table

var theadFlag = 0;
var thdeadData = "";
$(document).on('click', '#input_check', function(e) {
e.preventDefault();

if (theadFlag == 0) {
theadData = '<tr>' +
'<th>Nama Karyawan</th>' +
'<th>Tanggal</th>' +
'<th>Cost Center</th>' +
'<th>Jam Mulai</th>' +
'<th>Jam Selesai</th>' +
'<th>Status Lembur</th>' +
'<th>Total Jam</th>' +
'<th>Tugas</th>' +
'</tr>';

$('#body').append(theadData)
}


var nama = $('input[id="nama_check"]').val(),
bagian = $('input[id="tanggal_check"]').val(),
cost = $('input[id="cost_check"]').val(),
mulai = $('input[id="start"]').val(),
selesai = $('input[id="end"]').val(),
status = $('input[id="status_check"]').val();
total = $('input[id="total_jam"]').val(),
tugas = $('input[id="tugas_check"]').val(),

$('#body').append(

'<tr>' +
'<td>' + $("#nama_check").val() + '</td>' +
'<td>' + $("#tanggal_check").val() + '</td>' +
'<td>' + $("#cost_check").val() + '</td>' +
'<td>' + $("#start").val() + '</td>' +
'<td>' + $("#end").val() + '</td>' +
'<td>' + $("#status_check").val() + '</td>' +
'<td>' + $("#total_jam").val() + '</td>' +
'<td>' + $("#tugas_check").val() + '</td>' +
'</tr>');
theadFlag = 1;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<!-- The Modal -->
<div id="myMd4" class="md4">
<!-- Modal content -->
<div class="md4-content" style="margin-top:20px">
<div id="data">

<table border="1" style="margin-left:50px">
<tr>
<td>
<table border="1">
<tr>
<td>
<form action="../php/absen/absen_karyawan_autocomplete.php" id="form_check" method="post" name="form_check">
<table>
<tr>
<td width="50" style="border-left:hidden; border-right:hidden"></td>
<td width="150">Nama Karyawan</td>
<td width="10">:</td>
<td width="150"><input type="text" id="nama_check" type="text" name="nama_check" size="25" style="float:left; text-transform:uppercase"> </td>
<td width="10" style="border-left:hidden; border-right:hidden"></td>
<td width="150">Tanggal</td>
<td width="10">:</td>
<td width="150"><input type="text" id="tanggal_check" type="text" name="tanggal_check" size="25" style="float:left; text-transform:uppercase"></td>
</tr>
<tr>
<td width="50" style="border-left:hidden; border-right:hidden"></td>
<td width="150">Jam Mulai</td>
<td width="10">:</td>
<td><input type="time" id="start" name="logintime" style="float:left" /></td>

<td width="100" style="border-left:hidden; border-right:hidden"></td>
<td width="150">Jam Selesai</td>
<td width="10">:</td>
<td width="150"><input type="time" id="end" name="logouttime" style="float:left" /></td>

</tr>
<tr>
<td width="50" style="border-left:hidden; border-right:hidden"></td>
<td width="150">Status Lembur</td>
<td width="10">:</td>
<td width="150"><select name="option2" id="option2" onchange="Choose1(this)" style="float:left">
<option value="-">-</option>
<option value="istirahat">istirahat</option>
<option value="tanpa istirahat">tanpa istirahat</option>
</select><input type="text" name="status_check" size="8" readonly="readonly" id="status_check" style="text-transform:uppercase" /></td>
<td width="10" style="border-left:hidden; border-right:hidden"></td>
<td width="150">Total Jam</td>
<td width="10">:</td>
<td width="150"><input type="text" id="total_jam" type="text" name="total_jam" size="25" style="float:left; text-transform:uppercase"></td>
</tr>
<tr>
<td width="50" style="border-left:hidden; border-right:hidden"></td>
<td width="150">Cost Center</td>
<td width="10">:</td>
<td width="150"><input type="text" id="cost_check" type="text" name="cost_check" size="25" style="float:left; text-transform:uppercase"></td>
<td width="10" style="border-left:hidden; border-right:hidden"></td>
<td width="150">Tugas</td>
<td width="10">:</td>
<td width="150"><input type="text" id="tugas_check" type="text" name="tugas_check" size="25" style="float:left"></td>
</tr>
</table>
</form>
</td>
<td width="300">
<label class="button" name="input_check" id="input_check" style="height:35px; width:40px">CLICK HERE</label>
<label class="button" name="edit_karyawan" id="edit_karyawan" style="height:35px; width:40px">b</label>
<label class="button" name="delete_karyawan" id="delete_karyawan" style="height:35px; width:40px; ">c</label>
<label name="tutup" id="tutup" class="tutup" style="height:35px; width:40px;">d</label>


</td>

</tr>
<tr>
<td>
<p align="center"><strong>Test</strong></p>
<table id="check_data" class="check_data" style="font-size:12px; margin-left:70px ">
<tbody id="body">
</tbody>
</table>

<script>
function Choose1(data) {

document.getElementById("status_check").value = data.value;

}
</script>

关于javascript - 如何使 tbody 子级大小与 thead 之后创建的第一个 tbody 大小相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45076641/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com