[英]How do you add/edit attributes of input tag or class to DOM elements using php conditional statements?
I'm creating a visual table reservation system and in order to signify that a certain table is booked, it will become disabled. 我正在创建一个可视表预订系统,为了表示已预订某个表,它将被禁用。
*the code is not done yet but I'm trying to figure out first how I can add properties using jQuery inside a php conditional statement** *代码尚未完成,但我想先弄清楚如何在php条件语句中使用jQuery添加属性**
php code: php代码:
<?php
include "php/dbconn.php";
$sql = "SELECT id FROM place";
$tables = mysqli_query($conn, $sql);
while ($tablesrow = mysqli_fetch_array($tables)) {
$flag = false;
#check muna kung walang schedule conflict
$sql = "SELECT place FROM reservation WHERE status=0 AND (date='$date' AND starttime <=
'$endtime' AND endtime >='$starttime;')";
$bookedresult = mysqli_query($conn, $sql);
while ($bookedrow = mysqli_fetch_array($bookedresult)) {
if ($bookedrow["place"] == $tablesrow["id"]) {
$flag = true;
// echo $bookedrow["place"];
}
}
if (!$flag) {
// echo "<option>" . $tablesrow["id"] . "</option>";
echo "<script>";`
` Then the javascript inside (this is a continuation of php code) where I wish to add a disabled attribute to the input checkbox with id #tblc_1 `然后在里面的javascript(这是php代码的延续)中,我希望在ID为#tblc_1的输入复选框中添加一个禁用的属性
$(window).load(function () {$('#tbl-c').attr('disabled', true);});
This is for the html checkbox 这是用于html复选框
<div class="tbl-c-cont">
<div class="tbl-c tbl-c1">
<span>
<input type="checkbox" id="tblc_1" value="tblc_1" name="tbl_id[]">
</span>
</div>
<div class="tbl-c tbl-c2 ">
<span>
<input type="checkbox" id="tblc_2" value="tblc_2" name="tbl_id[]">
</span>
</div>
It doesn't work and I don't receive the achieved results. 它不起作用,我没有收到所取得的成果。
As per your question you have written wrong selector here. 根据您的问题,您在此处输入了错误的选择器。 it should be #tblc_1
instead of #tbl-c
. 它应该是#tblc_1
而不是#tbl-c
。 check updated snippet below 检查下面的更新的片段
$('#tblc_1').attr('disabled', true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="tbl-c tbl-c1"> <span> <input type="checkbox" id="tblc_1" value="tblc_1" name="tbl_id[]"> </span> </div> <div class="tbl-c tbl-c2 "> <span> <input type="checkbox" id="tblc_2" value="tblc_2" name="tbl_id[]"> </span> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.