开发人员,我是javascript新手。我创建的页面包括添加和取消好友按钮(禁用),每个按钮代表从注册页面获取数据ID。将按钮链接添加到提示框。在提示框中输入的数据将插入数据库。之后,该unfriend按钮将能够单击。为避免客户多次单击Add按钮,我在单击一次后放置了禁用选项。现在我的问题是可以插入数据,但是无法启用该按钮。
<html>
<script>
function myFunction(form) {
var subject = prompt("Please enter Subject that want to study");
form['add'].value = "request sent";
form['btn'].disabled = false;
form['add'].disabled = true;
if (subject != null) {
form['subject'].value = subject;
form.submit();
return false;
}
}
function unfriend(form) {
form["add"].disabled = false;
form["btn"].disabled = false;
form["add"].value = "Add friend";
form.submit();
return true;
}
</script>
<body>
<form method="post" id="form" enctype="multipart/form-data" autocomplete="off">
<input type="hidden" name="id" value="<?php echo $row['register_ID'];?>" />
<input type="hidden" id="subject" name="subject" data-uid=<?php echo $_SESSION[ 'sid'] ;?>/>
<td><input type="submit" onclick="myFunction(this.form);" name="addfriend" data-type='addfriend' id="add" class="btn" value="add" />
<input type="submit" value="unfriend" id="btn" onclick="unfriend(this.form);" disabled /> </td>
</form>
if(isset($_POST['subject']) and $_POST['id']) { $user_id = $_SESSION['sid']; $friend_id = $_POST['id']; $status = "yes"; $subject=$_POST['subject']; $sql="INSERT INTO friends(user_id,status,subject,friend_id)" ."VALUES('$user_id','yes','$subject','$friend_id')
"; if($mysqli->query($sql)=== true) { $_SESSION['status']="yes"; $_SESSION['friend_id']=$friend_id; $_SESSION['user_id'] = $user_id; } else { } }?>
</body>
</html>