我试图通过 ajax 将一些数据传递给 php 文件,但前提是单击一个元素。
如何将每个 A 元素附加到相应的 JS 函数,并且只单击一次?
<a class="rating star1">1</a><br />
<a class="rating star2">2</a><br />
<a class="rating star3">3</a><br />
<script>
//CANT WORK OUT HOW TO ACTIVATE THIS FUNCTION ONLY IF .star1 IS CLICKED
function() {
$.post('/rate.php', {
rating : '1',
page_id : '1234'
}, function(){
});
}
//CANT WORK OUT HOW TO ACTIVATE THIS FUNCTION ONLY IF .star2 IS CLICKED
function() {
$.post('/rate.php', {
rating : '2',
page_id : '1234'
}, function(){
});
}
//CANT WORK OUT HOW TO ACTIVATE THIS FUNCTION ONLY IF .star3 IS CLICKED
function() {
$.post('/rate.php', {
rating : '3',
page_id : '1234'
}, function(){
});
}
</script>