1
データベースからの結果が表示される動的なテーブルがあります。phpでボタンの値を取得し、JavaScriptで処理します。
<table id="table" class="table datatable-responsive">
<thead>
<tr class="bg-teal">
<th>#</th>
<th>Datum & Vrijeme</th>
<th>Stavka</th>
<th><center>Izabrana količina</center></th>
<th><center><i class="icon-pencil"></i></center></th>
<th><center><i class="icon-bin"></i></center></th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
while ($r=$q->fetch()) {
$a = 0;
$a += 1;
$id = $r['Id'];
$datum = $r['Datum'];
$time = date("H:i:s",strtotime($datum));
$time2 = date("d/m/Y",strtotime($datum));
$stavka = $r['Stavka'];
$kolicina = $r['Kolicina'];
?>
<tr>
<td><?php echo $i; $i++; ?></td>
<td><?php echo $time2 .' & '.$time; ?></td>
<td><?php echo $stavka; ?></td>
<td class="nr"><center><?php echo $kolicina; ?></center></td>
<td><center><button type="button" value="<?php echo $id?>" name="izmjena" onClick="showDiv()"><i class="icon-pencil text-danger"></i></center></button>
</td>
<td><center><button type="submit" value="<?php echo $id ;?>" name="brisi" class="icon-bin text-danger"></button></center></td>
</tr>
<?php } ?>
</tbody>
<!--<a onClick="window.open('edit/korpa.php?id= <?=$r['Id']?>','E-cart','width=800,height=500,left=0,top=100,screenX=0,screenY=100,menubar=yes,scrollbars=yes')"> -->
</table>
表には「Kolicina」を編集するためのボタンがあります。一度ボタンをクリックすると、divを開く必要があります。
divでは、値を渡してjsを使用して値を出力する必要があります。私がそれをしたら、私はPHPでdbに保存する必要があります
下記のボタンdivをクリックすると、それは動作します。
<div class="col-lg-9" id="IzmjenaDiv" style="display:none;" >
<div class="panel panel-flat">
<table class="table table-bordered">
<tr>
<th class="">Količina</th>
<td class=""><input type="text" id="id" value="" class="form-control text-info border-info"></td>
<td class=""><input type="text" id="kolicina" name="kolicina" placeholder="Upišite novu količinu" class="form-control text-danger border-danger"></td>
<td class="">
<select class="form-control" id="mjera" name="mjera">
<option value="KG">KG </option>
<option value="KOM">KOM </option>
</select>
</td>
</tr>
</table><hr/>
<div class="pull-right">
<button type="button" class="btn btn-success btn-sm" onclick="savechanges()"> Snimi <i class="icon-play3 position-right"></i></button>
</div>
<br/><br/><br/>
</div>
</div>
行「Kolicina」のボタン1から2つの値を取得するスクリプトを作成する必要があります。次に、divの値をクリックして表示する必要があります。 スクリプトを作成しましたが、開こうとしているdivを自動的に閉じます。
<script>
function showDiv() {
document.getElementById('IzmjenaDiv').style.display = "block";
var y = $(object).parent("center").parent("td").parent("tr").find(".nr center").text();
var x = $(object).attr("value");
window.location.href = "korpa.php?w1=" + x + "&w2=" + y;
}
</script>
任意のアドバイスを
それは空です。何も表示されません – user3651819
もう一度お試しいただけますか? –
これは良いですが、私はidの値を得ましたが、問題はスクリプトにありますので、自動的にdiv i openを閉じます – user3651819