首页 > 解决方案 > 将值传递到 Bootboxjs 对话框确认框

问题描述

我有一个PHP这样的 foreach 循环:

<?php
foreach ($student->student as $d) {
    echo
    '<tr>' 
        '<td class="StudentID">' . $d->ID . '</td>' .
        '<td>' . $d->Date . '</td>' .
        '<td>' . $d->Name . '</td>' .
        '<td><a class="show-confirmation">'. "click to confirm" . '</a></td>' .
    '</tr>';
}
?>

我正在使用这样bootbox js的对话框:

<script>
    $(document).on("click", ".show-confirmation", function(e) {
        var StudentID = $('#StudentID').val();

        bootbox.confirm("Confirm, student ID? " + StudentID, function(result) {
            console.log('This was logged in the callback: ' + result);
            console.log('StudentID: ' + StudentID);
        });
    });
</script>

我想要完成的是当我单击click to confirmwhich has时class="show-confirmation",我想$d->IDbootbox js确认对话框中获取 的值。由于这是一个for each循环,我想每次在对话框确认框上传递一个新的学生 ID。

在确认对话框中,我想查看Confirm, student ID? + 15该行的学生 ID。

我做了什么?

有人可以指导我完成这个方法吗?

标签: javascriptphpbootbox

解决方案


$('#StudentID')正在寻找一个将其设置为类的 id 属性的元素。改为$('.StudentID')改为。


推荐阅读