从图像OnClick事件执行PHP函数 [英] Execute a PHP function from image OnClick event
本文介绍了从图像OnClick事件执行PHP函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个PHP类,其中有一个 delete
函数。当我点击我要调用的图像时删除
,但这行不起作用:
I have a PHP class in which there is a delete
function. When I click on the image I want to call delete
, but this line is not working:
echo "<img src='icon/del.gif' onClick='.delete().'/>"
我尝试过使用 href
标签但是它不起作用。
I have tried using the href
tag but it doesn't work.
推荐答案
考虑到你可以使用jQuery,你需要做以下事情:
Considering you can use jQuery, you need to do the following:
首先给你的img一个类,例如:
first give your img a class, for example:
<img src="/icon/del.gif" class="delete" />
然后使用jquery绑定它:
then bind this using jquery:
$('.delete').click(function(){
$.ajax({
type: 'POST',
url: '/url/to/your_php_script.php',
data: {'id':'45'}
}
});
});
你的php文件被执行并且$ _POST ['id']被发送给它。
your php file gets executed and $_POST['id'] gets send to it.
这有帮助吗?你自己可以休息一下吗?如果没有,请给我们更多代码:)
does this help? can you do the rest yourself? if not, give us more code :)
这篇关于从图像OnClick事件执行PHP函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文