使用onclick执行PHP函数我正在寻找一个简单的解决方案,只有在单击a-tag时调用PHP函数。PHP:function removeday() { ... }HTML:<a href="" onclick="removeday()" class="deletebtn">Delete</a>更新: html和PHP代码在同一个PHP文件中
3 回答
扬帆大鱼
TA贡献1799条经验 获得超9个赞
在javascript中,创建一个ajax函数,
function myAjax() {
$.ajax({
type: "POST",
url: 'your_url/ajax.php',
data:{action:'call_this'},
success:function(html) {
alert(html);
}
});
}然后从html调用,
<a href="" onclick="myAjax()" class="deletebtn">Delete</a>
在你的ajax.php中,
if($_POST['action'] == 'call_this') {
// call removeday() here}添加回答
举报
0/150
提交
取消
