gpt4 book ai didi

javascript - 确认后禁用单选按钮

转载 作者:行者123 更新时间:2023-11-28 04:08:38 25 4
gpt4 key购买 nike

我尝试研究并尝试了很多选择,但仍然不起作用。用户单击单选按钮并确认后,我需要禁用单选按钮

<script type="text/javascript">
function getVote(int) {
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();

} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

if (confirm("Your vote is for " + int)) {

xmlhttp.open("GET", "save.php?vote=" + int, true);
xmlhttp.send();
window.location.reload();

} else {
alert("Choose another candidate ");
}

}

function getPosition(String) {
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.open("GET", "vote.php?position=" + String, true);

xmlhttp.send();

}
</script>

这是用户将单击的单选按钮

     echo "<td><input type='radio' name='vote' value='$row[candidate_name]' onclick='getVote(this.value)' /></td>";

当用户单击单选按钮时,这是 save.php

   <?php
require('connection.php');
$vote = $_REQUEST['vote'];

$checkposition=mysql_query("SELECT candidate_position FROM voting_tbCandidates WHERE candidate_name='$vote'");
while ($row=mysql_fetch_array($checkposition)){
session_start();

if($row['candidate_position']=="PRESIDENT"){
$_SESSION['vote_president']=$row['candidate_position'];
}elseif($row['candidate_position']=="VICE"){
$_SESSION['vote_vice']=$row['candidate_position'];
}elseif($row['candidate_position']=="MUSE"){
$_SESSION['vote_muse']=$row['candidate_position'];
}elseif($row['candidate_position']=="SECRETARY"){
$_SESSION['vote_secretary']=$row['candidate_position'];
}elseif($row['candidate_position']=="ESCORT"){
$_SESSION['vote_escort']=$row['candidate_position'];
}elseif($row['candidate_position']=="AUDITOR"){
$_SESSION['vote_auditor']=$row['candidate_position'];
}
}
mysql_query("UPDATE voting_tbCandidates SET candidate_cvotes=candidate_cvotes+1 WHERE candidate_name='$vote'");

mysql_close($con);
?>

最佳答案

您仅将值发送回函数。将整个元素发送到函数并挑选出您需要的部分会更容易。例如:改变

onclick='getVote(this.value)'

onclick='getVote(this)'

改变

function getVote(int) 

function getVote(obj) {
var int = obj.value;

xmlhttp.open("GET", "save.php?vote="+ int, true); 之前添加以下行

obj.setAttribute('disabled','disabled'); // I think this would work

关于javascript - 确认后禁用单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46482669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com