1
現在、私は編集を終えた後に行を編集して保存できるテーブルを持っています。電子メールセルに電子メールが含まれていない場合は保存しないなど、検証を追加できるようにしたいと考えています。私は保存をクリックしてフィールドが検証されていない場合、エラーを表示するダイアログボックスを表示したいと思います。これどうやってするの?ここでテーブルの行を編集するときの検証の追加
は、私は必要なものである:
Buyer ID - numbers only
POC Name - text only
POC Email - email only
POC Phone - phone number only
相対HTML/PHP:
<?php
foreach ($dbh->query($sql) as $rows){
?>
<tr>
<td class="mr_id" contenteditable="false"><?php echo intval ($rows['MR_ID'])?></td>
<td class="mr_name" contenteditable="false"><?php echo $rows['MR_Name']?></td>
<td class="buyer_id" contenteditable="false"><?php echo $rows['Buyer_ID']?></td>
<td class="poc_n" contenteditable="false"><?php echo $rows['MR_POC_N']?></td>
<td class="poc_e" contenteditable="false"><?php echo $rows['MR_POC_E']?></td>
<td class="poc_p" contenteditable="false"><?php echo $rows['MR_POC_P']?></td>
<td><button class="edit" name="edit">Edit</button>
<button class="delRow" name="delete" onclick="deleteRow(this)">Delete</button></td>
</tr>
相対Javascriptを:
$(document).ready(function() {
$('.edit').click(function() {
var $this = $(this);
var tds = $this.closest('tr').find('td').not('.mr_id').filter(function() {
return $(this).find('.edit').length === 0;
});
if ($this.html() === 'Edit') {
$this.html('Save');
tds.prop('contenteditable', true);
} else {
$this.html('Edit');
tds.prop('contenteditable', false);
}
});
});