我想从php代码中调用javascript函数myfunction()。守则如下:
<script>
function myfunction() {
var r = confirm("Are you sure ? ");
if (r == true) {
//delete file from database with id b_id
}
<?php header("Refresh:0"); ?>
}
</script>我想从这个php代码中调用js函数。
<?php
while(//fetched database elements one by one)
{
//$b_id fetched from database.
echo "<button class='w3-display-topright pe-7s-close-circle w3-xxlarge w3-button' onclick="myfunction($b_id);"></button>
}
?>发布于 2017-09-05 04:59:37
编写另一个PHP脚本,根据ID删除条目并从网页中调用它。也就是说,
<?
while (...) {
echo "<button onclick='deleteEntry($id)'></button>"
}
?>你的JS是这样的:
function deleteEntry(id) {
if (confirm('Are you sure?')) {
fetch('myserver/delete_entry.php?id=' + id);
}
}当然,你必须写delete_entry.php。
https://stackoverflow.com/questions/46046737
复制相似问题