首先检查后,我是否需要帮助您禁用复选框。
这是我到目前为止所做的。
<?php
include_once('db_connect.php');
$lokotitle = $description = $category = $showyourname = $yourname = $lat = $lng = "";
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$lokotitle=$_POST['lokotitle'];
$description=$_POST['description'];
$category=$_POST['category'];
$showyourname=$_POST['showyourname'];
$yourname=$_POST['yourname'];
$lat=$_POST['lat'];
$lng=$_POST['lng'];
// Validation will be added here
if(empty($lokotitle)) {
$error_message = "Please input a Loko title.";
?><script>$('#notitle'.text($error_message));</script><?php
exit;
}
if(!isset($error_message)){
//Inserting record in table using INSERT query
$insqDbtb="INSERT INTO `new`.`web_form`
(`lokotitle`, `description`, `category`, `showyourname`, `yourname`, `lat`, `lng`) VALUES ('$lokotitle', '$description', '$category', '$showyourname', '$yourname', '$lat', '$lng')";
mysqli_query($link,$insqDbtb) or die(mysqli_error($link));
?><script>window.location.href = "../index.php"; </script> <?php
exit;
}
}
?>
答案 0 :(得分:0)
更改
$(this).attr('disabled','disabled');
to
$('#checked').attr('disabled', true);
因为$(this)不是指复选框,因为你在函数体内。
答案 1 :(得分:0)
请检查此代码段。
function check() {
if($("#checked").is(":checked")){
alert("Thanks for Attending");
//Code to disable checkbox after checked
$('#checked').attr('disabled', true);
}
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label class="checkbox-inline"><input type="checkbox" id="checked" onclick="check();"></label>
&#13;
答案 2 :(得分:0)
使用vanilla js的另一种选择,因为你试图将它与jQuery结合起来,而你却不能这样做:
function check() {
var el = document.getElementById("checked");
if (el.checked) {
el.disabled = true;
}
}
如果你仍然需要jQuery版本坚持.prop()
用法:
function check() {
var $el = $("#checked");
if ($el.is(":checked")) {
$el.prop("disabled", true);
}
}
答案 3 :(得分:0)
<html>
<head>
<title>JqueryCheckboxChekedDisableCheckbox</title>
<style>
input[type=text] {
width: 100%;
height:10%;
padding: 6px;
border: 1px solid #ccc;
border-radius: 4px;
}
label {
padding: 12px 12px 12px 0;
display: inline-block;
font-family:sans-serif;
}
input[type=submit] {
background-color: #4CAF50;
border: none;
color: white;
padding: 6px 20px;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
}
.error{
color:red;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<fieldset style="margin-left:20%;margin-right:20%;font-family:sans-serif;padding:15px;border-radius:5px;background:#f2f2f2;border:5px solid #1F497D">
<legend style="background:#1F497D;color:#fff;padding:5px 10px;font-size:22px;border-radius:5px;margin-left:20px;box-shadow:0 0 0 5px #ddd">JqueryCheckboxChekedDisableCheckbox</legend>
<table>
<tr><td>Subjects:</td><td><input type="checkbox" name="subject" value="java"/>Java<input type="checkbox" name="subject" value="hibernate"/>Hibernate<input type="checkbox" name="subject" value="spring"/>Spring</td></tr>
<tr><td></td><td><input type="submit" value="Submit" id="send"/></td></tr>
</table>
</fieldset>
</html>
<script>
$('#send').on('click',function(){
$("input[name='subject']").each(function(){
if ($(this).is(":checked")) {
$(this).prop("disabled",true);
}
});
});
</script>