href 多链接图像
我不确定这是否是执行此操作的最佳方式,但我的页面上有一些图像,并且希望每个图像都有不同的操作。下面的在单击时向数据库添加一条记录,如果我想添加另一张图像以单击删除,如何使其唯一以便我的 .click
函数可以启动delete.php 文件? (如您所见,数据目前是硬编码的)
<a href=""><img src="/wp-content/themes/Atlantis/images/add.gif" /></a>
<script type="text/javascript">
$(document).ready(function() {
$("a").click(function() {
$.ajax({
url: 'add.php',
data: "Masterselect=11&UserID=55&Status=W",
dataType: 'json',
});
alert("Thanks for adding");
});
});
</script>
I'm not sure if its the best way of doing this, but I have a few images on my page, and want each of them to have a different action. The one below adds a record to a database when clicked, if I want to add another image to click to delete, how do I make it unique so my .click
function can launch a delete.php file? (data is hard coded at the moment as you can see)
<a href=""><img src="/wp-content/themes/Atlantis/images/add.gif" /></a>
<script type="text/javascript">
$(document).ready(function() {
$("a").click(function() {
$.ajax({
url: 'add.php',
data: "Masterselect=11&UserID=55&Status=W",
dataType: 'json',
});
alert("Thanks for adding");
});
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会给你的链接命名——给它们一个类或id属性
然后你可以为添加按钮指定一个函数,为删除指定另一个函数,依此类推:
I would name your links -- give them a class or id attribute
And then you could specify one function for the add button, another for the delete, and so on:
只需在那里放置一些独特的东西,这样您就可以做到这一点,也许可以通过在链接
delete
中添加一个类来实现。然后只需
$('.delete')
,其余的应该是显而易见的。Just put something unique there so you can do it, perhaps by adding a class to your link
delete
.Then just
$('.delete')
and the rest should be obvious.您可以为图像定义一个类名称,将其作为点击事件而不是 ahref
为图像类提供点击事件,
在此处添加点击事件
}
You can define a class name for image give it as click event instead of ahref
give click event for image class
add click events here
}