我有一个问题,我正在研究这几天而且我被卡住了。我想做的事?我想将$ id通过url传递给modal,女巫打开点击并打开表格,我可以使用php从mysql编辑/更新数据! 当我按下编辑时,我在网址中获取数据和人员ID但模态没有打开。我认为我的脚本/ jquery是错误的,有人可以看看并帮助我。!!
当我按下编辑按钮时,我会在网址中显示此内容但没有打开?!?!
http://localhost/zadatak_senso/index.php?poslovni_korisnici#update_poslovni=34
模态 - > m_update_ok.php
<?php
// ---- Pocetak modal-a za update poslovnih korisnika ---- //
echo'
<div class="modal fade bs-example-modal-lg" id="update_poslovni">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Uredi</span></button>
<h4 class="modal-title">Unos poslovnih korisnika</h4>
</div>
<div class="modal-body">';
if (isset($_POST['submit_upk'])) {
$partnername = $_POST['partner_name'];
$partnerstreet = $_POST['partner_street'];
$partnerzip = $_POST['partner_zip'];
$partnercity = $_POST['partner_city'];
$partnercountry = $_POST['partner_country'];
$sql = "UPDATE poslovni_partneri
SET
Partner_name = '$partnername',
Partner_street = '$partnerstreet',
Partner_zip = '$partnerzip',
Partner_city = '$partnercity',
Partner_country = '$partnercountry'
WHERE Partner_id = '$id'";
// Prepare statement
$stmt = $dbh->prepare($sql);
// execute the query
$stmt->execute();
}
echo'
<form method="POST" target="_parent" >
<table id="table_id" class="display">
<thead>
<tr>
<th>Partner name</th>
<th>Partner street</th>
<th>Partner zip</th>
<th>Partner city</th>
<th>Partner country</th>
</tr>
</thead>
<tbody>';
$id = $_GET['Partner_id'];
$sql = "SELECT * FROM poslovni_partneri WHERE Partner_id LIKE '$id'";
$stmt = $dbh->query($sql);
$row =$stmt->fetchObject();
$partner_name = $row['partner_name'];
$partner_street = $row['partner_street'];
$partner_zip = $row['partner_zip'];
$partner_city = $row['partner_city'];
$partner_country = $row['partner_country'];
echo'
<tr>
<td><input type="text" name="partner_name" value="'.$partner_name.'">'.$partnername.'</td>
<td><input type="text" name="partner_street" value="'.$partner_street.'">'.$partnerstreet.'</td>
<td><input type="text" name="partner_zip" value="'.$partner_zip.'">'.$partnerzip.'</td>
<td><input type="text" name="partner_city" value="'.$partner_city.'">'.$partnercity.'</td>
<td><input type="text" name="partner_country" value="'.$partner_country.'">'.$partnercountry.'</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<input type="submit" name="submit_upk" value="Uredi" />
</div>
</form>
</div>
</div>
</div>
<script>
<script>
$(function(){
$("a.update_poslovni").click(function(e)
{
event.preventDefault(); // for the <a href="#" not to fire
var bookId = $(this).data("book-id");
$("#update_poslovni").find("input[name="bookId"]").val(bookId);
$("#update_poslovni").dialog({modal: true});
});
});
</script>
</script>';
// ---- Kraj modal-a za update poslovnih korisnika ---- //
?>
的index.php
echo' <table id="table_id" class="display">
<thead>
<tr>
<th>Partner name</th>
<th>Partner street</th>
<th>Partner zip</th>
<th>Partner city</th>
<th>Partner country</th>
<th></th>
<th><a href="edit.php?editPoslovni="><button type="button" class="btn btn-default btn-sm">Delete</button></a></th>
</tr>
</thead>
<tbody>';
$sql = "SELECT * FROM poslovni_partneri";
foreach ($dbh->query($sql) as $row)
{
echo'
<tr>
<td>'.$row['Partner_name'].'</td>
<td>'.$row['Partner_street'].'</td>
<td>'.$row['Partner_zip'].'</td>
<td>'.$row['Partner_city'].'</td>
<td>'.$row['Partner_country'].'</td>
<td><a href="#update_poslovni='.$row['Partner_id'].'" class="btn btn-default btn-sm" data-toggle="modal" data-id="'.$row['Partner_id'].'">Edit</a></td>
<td><input type="checkbox" id="blankCheckbox" value="option1" aria-label="..."></td>
</tr>';
}
echo'
</tbody>
</table>';
答案 0 :(得分:0)
从网址获取哈希:How can you check for a #hash in a URL using JavaScript?
获得哈希后,使用哈希的id选择器获取元素,然后:
$(hash).modal('show')