【问题标题】:How do I make the other tab content working the same as the active tab?如何使其他选项卡内容与活动选项卡相同?
【发布时间】:2019-09-22 07:40:36
【问题描述】:

第一个选项卡工作正常,但是当我将其复制并粘贴到其他选项卡的内容时,它无法正常工作。我有一个显示当前日期的日期输入,但也可以编辑选项卡内容包含显示数据的表。当您单击中期选项卡时,它不会在表格内显示数据,日期也不会显示我与 javascript/jquery 一起使用的当前日期。

 <div class="container">
            <div class="col-lg-12">
                <ul class="nav nav-tabs" role="tablist">
                    <li class="nav-item">
                        <a data-toggle="tab" class="nav-link active" href="#prelim">Prelim</a>
                    </li>
                    <li class="nav-item">
                        <a data-toggle="tab" class="nav-link" href="#midterm">Midterm</a>
                    </li>
                </ul>

                <!-- Tab panes -->
                <div class="tab-content">
                    <div id="prelim" class="container tab-pane active"><br>
                        <div class="row">
                            <div class="form-inline form-padding">
                                <div class="col-sm">
                                    <label>Date:</label>
                                </div>
                                <div class="col-sm">                          
                                    <input type ="date" id="todays-date" value="" class="form-control" name="date" required>

                                </div>
                            </div>
                        </div>
                        <br />
                        <div class="table-responsive">
                            <table id="dtable" class="table table-striped table-hover table-bordered">
                                <thead class="bg-dark text-light">
                                    <tr>
                                        <th class="text-center">Student ID</th>
                                        <th class="text-center">Student Name</th>
                                        <th class="text-center">Status</th>
                                    </tr>
                                </thead>
                                <tbody>
                                <?php while($row = mysqli_fetch_array($rss)): ?>
                                <?php
                                    $studid = $row['student_id'];
                                    $stud = mysqli_query($mysqli,"select * from tbl_student where stud_id = '$studid'");
                                    $rs= mysqli_fetch_array($stud);  
                                ?>
                                    <tr>
                                        <td class="text-center"><?php echo $studid; ?></td>
                                        <td><?php echo $rs['stud_lname'];?>, <?php echo $rs['stud_fname'];?> <?php echo $rs['stud_mname'];?> <?php echo $rs['stud_suffix'];?></td>
                                        <td class="text-center">
                                            <a Title="Present" href='' onclick="this.href='action/actionclass.php?present&classid=<?php echo $classid; ?>&studid=<?php echo $studid;?>&period=Prelim&date='+document.getElementById('todays-date').value"><i class="fas fa-check fa-2x text-success"></i></a>&nbsp;
                                            <a Title="Absent" href='' onclick="this.href='action/actionclass.php?absent&classid=<?php echo $classid; ?>&studid=<?php echo $studid;?>&period=Prelim&date='+document.getElementById('todays-date').value"><i class="fas fa-times fa-2x text-danger"></i></a>
                                        </td>
                                    </tr>
                                    <?php $c++; ?>
                                    <?php endwhile; ?>
                                    <?php if(mysqli_num_rows($rss) < 1): ?>
                                    <tr>
                                        <td colspan="3" class="text-center text-danger"><h5>*** EMPTY ***</h5></td>
                                    </tr>
                                    <?php endif;?>
                                </tbody>
                            </table>
                        </div>
                    </div>

本节开始第二个标签内容。

                    <div id="midterm" class="container tab-pane fade"><br>
                        <div class="row">
                            <div class="form-inline form-padding">
                                <div class="col-sm">
                                    <label>Date:</label>
                                </div>
                                <div class="col-sm">                          
                                    <input type ="date" id="todays-date" value="" class="form-control" name="date" required>

                                </div>
                            </div>
                        </div>
                        <br />
                        <div class="table-responsive">
                            <table id="dtable" class="table table-striped table-hover table-bordered">
                                <thead class="bg-dark text-light">
                                    <tr>
                                        <th class="text-center">Student ID</th>
                                        <th class="text-center">Student Name</th>
                                        <th class="text-center">Status</th>
                                    </tr>
                                </thead>
                                <tbody>
                                <?php while($row = mysqli_fetch_array($rss)): ?>
                                <?php
                                    $studid = $row['student_id'];
                                    $stud = mysqli_query($mysqli,"select * from tbl_student where stud_id = '$studid'");
                                    $rs= mysqli_fetch_array($stud);  
                                ?>
                                    <tr>
                                        <td class="text-center"><?php echo $studid; ?></td>
                                        <td><?php echo $rs['stud_lname'];?>, <?php echo $rs['stud_fname'];?> <?php echo $rs['stud_mname'];?> <?php echo $rs['stud_suffix'];?></td>
                                        <td class="text-center">
                                            <a Title="Present" href='' onclick="this.href='action/actionclass.php?present&classid=<?php echo $classid; ?>&studid=<?php echo $studid;?>&period=Midterm&date='+document.getElementById('todays-date').value"><i class="fas fa-check fa-2x text-success"></i></a>&nbsp;
                                            <a Title="Absent" href='' onclick="this.href='action/actionclass.php?absent&classid=<?php echo $classid; ?>&studid=<?php echo $studid;?>&period=Midterm&date='+document.getElementById('todays-date').value"><i class="fas fa-times fa-2x text-danger"></i></a>
                                        </td>
                                    </tr>
                                    <?php $c++; ?>
                                    <?php endwhile; ?>
                                    <?php if(mysqli_num_rows($rss) < 1): ?>
                                    <tr>
                                        <td colspan="3" class="text-center text-danger"><h5>*** EMPTY ***</h5></td>
                                    </tr>
                                    <?php endif;?>
                                </tbody>
                            </table>
                        </div>
                    </div>
</div>
</div>
</div>

【问题讨论】:

    标签: javascript php tabs


    【解决方案1】:

    当您执行while($row = mysqli_fetch_array($rss)) 时,它将循环直到没有更多行可以获取。

    然后当您再次执行while($row = mysqli_fetch_array($rss)) 时,它将循环直到没有更多行要获取,而是从上次停止的位置(最后一行之后)开始。

    如果这是你应该能够添加的问题

    mysqli_data_seek($rss, 0);

    就在你的第二个 while 循环之上,告诉它从第一行重新开始。

    【讨论】:

    • 成功了。先生非常感谢您!一个javascript怎么样? &lt;script&gt; var today = new Date(); var dd = ("0" + (today.getDate())).slice(-2); var mm = ("0" + (today.getMonth() + 1)).slice(-2); var yyyy = today.getFullYear(); today = yyyy + '-' + mm + '-' + dd ; $("#todays-date").attr("value", today); &lt;/script&gt;
    • 我可以看到的那个 javascript 没有问题。它没有做你想做的事吗?
    • 它应该显示当前日期。它出现在第一个选项卡上,但不在下一个选项卡上。
    • $("#todays-date") 将始终返回第一个匹配元素。您可以将$("#todays-date") 更改为$(".todays-date") 并将todays-date 添加到输入的class 属性中。
    • 从技术上讲,您永远不应拥有多个具有相同 id 的 html 元素,但您可以拥有尽可能多的具有相同 class 的元素。
    猜你喜欢
    • 2020-01-25
    • 1970-01-01
    • 2018-06-08
    • 2016-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多