doubiao9775 2017-05-29 09:41
浏览 71

如何使用php条件语句向DOM元素添加/编辑输入标签或类的属性?

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 code:

<?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

$(window).load(function () {$('#tbl-c').attr('disabled', true);}); 

This is for the html checkbox

<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.

  • 写回答

1条回答 默认 最新

  • duanbu1421 2017-05-29 09:52
    关注

    As per your question you have written wrong selector here. it should be #tblc_1 instead of #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>

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line