jquery - 将数据传递给 Bootstrap 模式

标签 jquery bootstrap-modal

经过大量搜索后,我找到了许多将数据传递到模型的解决方案,但没有任何效果,这是我的代码,可以指出我在哪里犯了错误吗?当我点击我的模型时,什么也没有显示。我可以通过 PHP 做到这一点吗?没有使用 javascript

<td>
    <a data-id="<?echo $comments;?>" class="open-AddBookDialog" href="#myModal"><?echo substr($comments,0,10)?></a>
</td>

<div class="modal fade" id="#myModal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Modal Header</h4>
            </div>
            <div class="modal-body">
                <p>
                    Some text
                </p>
                <input type="text" name="bookId" id="bookId" value="" />
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

Jquery

 $(document).on("click", ".open-AddBookDialog", function (e) {

    e.preventDefault();

    var _self = $(this);

    var myBookId = _self.data('id');
    $("#bookId").val(myBookId);

    $(_self.attr('href')).modal('show');
});

最佳答案

更改此:

<div class="modal fade" id="#myModal" role="dialog">

对此:

<div class="modal fade" id="myModal" role="dialog">

...没有“#”

关于jquery - 将数据传递给 Bootstrap 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31399280/

相关文章:

jquery - div 中的流体跨度宽度

javascript - 尝试动态分割字符串不断出现错误?

html - 当页面上有 iframe 时,Bootstrap 模式弹出窗口不起作用

javascript - 查询庞大的Json数据

jquery - 如何在动画功能期间执行动画功能?

javascript - 使用 javaScript/jQuery 显示/隐藏 html 表条目?

python - 将数据从数据表传递到模式Django

javascript - 所有其他代码运行后出现模态弹出加载屏幕

php - 使用 MySQL 数据库中的详细信息将动态创建的一组图像中的数据动态传递到 Modal

javascript - 用于检查 Angular Bootstrap 模态范围的 Jasmine 单元测试