[英]How to pass a string to a bootstrap modal?
我不确定自己在做什么错,但是我搜索了所有“将数据传递给引导程序模式”的帖子,但仍然找不到答案。
我与用户有一张桌子。 每行中都有一个“删除用户按钮”。 当您单击“删除”时,将显示一个模式,其中显示以下图例:“确定要删除吗?”
我希望用户名显示在该图例中,因此我将用户名发送到JS文件,但未显示。 什么也没出现。
这是每一行中的删除按钮:
<td><a href="#" onclick="callToModal({$frontuser->username});return false;" class="btn mini red-stripe" role="button" >Delete</a></td>
我使用的是smarty,这就是参数看起来像这样的原因: {$frontuser->username}
在该代码上方,我具有模态的定义:
<!-- modal -->
<div id="myModal3" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h3 id="myModalLabel3"></h3>
</div>
<div class="modal-body">
<p></p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cerrar</button>
<button data-dismiss="modal" class="btn blue" id="deleteok">Confirmar</button>
</div>
</div>
<!-- end modal -->
然后我的JS文件是:
function callToModal(data) {
$("#myModal3 .modal-header h3").html("Eliminar");
$("#myModal3 .modal-body p").html("Are you sure you want to delete: ", data);
$("#myModal3").modal("show");
}
任何帮助将非常感激!
最后,在搜索了smarty和js sintax之后,我发现了问题所在。
简单来说,它需要一些''包装参数。
因此,从SMARTY向JS发送参数的正确方法是:
<td><a href="#" onclick="callToModal('{$frontuser->username}');" class="btn mini red-stripe" role="button" >Eliminar</a></td>
为什么在.html()调用中包含逗号? 简单的错字吧?
$("#myModal3 .modal-body p").html("Are you sure you want to delete: ", data);
看起来“数据”的名称是否来自删除行中的函数调用? 如果您要这样做,只需将逗号更改为+即可将名称添加到字符串中。
$("#myModal3 .modal-body p").html("Are you sure you want to delete: "+ data);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.