我需要一个脚本来改变一个链接,当它被点击到另一个内容
我正在学生监督项目。我想创建一个包含可用项目主题的页面,当点击感兴趣的主题时,使用该“id”为用户分配主题并呈现链接不可用,例如,具有“可用”链接的主题可以更改到'不可用'。我需要一个脚本来改变一个链接,当它被点击到另一个内容
如果房子里有人可以帮忙,我真的会妄想吗?
感谢
您需要使用AJAX的,那是方式使用jQuery帮助您在实时的变化
我做了一些小改动来执行使用jQuery这个动作
<body>
<table cellspacing="2" cellpadding="2" border="2">
<?php $sql = "Select * from prject_topic"; $result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($result)) { ?>
<tr>
<td><?php echo $row['lecturer_name'];?></td>
<td><?php echo $row['topic'];?></td>
<td><span class="actu" id="<?php echo $row['project_id'];?>">
<?php echo $row['status'];?>
</span>
</td>
</tr> <?php } ?>
</table>
<script type="text/javascript">
$(function(){
//We capture the Click in the user item
$(".actu").on('click', function(){
//We take the ide of this item
var id = $(this).attr('id');
//We check the current status of the user
if($(this).html() == "Deactivate"){
var est = "Activate";
}else{
var est = "Deactivate";
}
//We made a request of type ajax sending by post the id for its update
$.post('#.php',
{
'id':id,
'est':est
},
//We received the response from our php file which may be a code as in the example...
function(data){
if(data=="200"){
//If yes, update the content of the selected item in real time
$("#"+id).html('Deactivate');
}else{
//In case of error, we send the information
alert("Unable to disable user");
}
})
})
})
</script>
</body>
该代码是为了您的理解而编写的
在响应函数中,您必须将选择代码的印象放在变量est中,我错过了那里... –
例如:'$(“#”+ id).html(est);' –
卡洛斯感谢这个剧本。我成功使用mysqli更新功能。 – nwafeolie
感谢Carlos Quintero。请问你能帮我完整的脚本吗? – nwafeolie
好了给我你的代码来分析它 –