![](/img/trans.png)
[英]How can I properly combine this simple javascript into this tiny php snippet?
[英]How to properly combine PHP result in this javascript line?
我有使用bootbox,js的确认警报。 在启动箱中,允许用户创建自定义html表单。 但是,我有一些表单元素/值是从PHP foreach填充的。 我试过这样写,但是没有用。 警报未触发。
bootbox.confirm({
title : "Testing",
message :
"<form id='test'>\
<h3>Dept: </h3>\
<table width='100%' cellspacing='0' cellpadding='3px'>\
<?php foreach($dept as $row_dept){ ?>
<tr>\
<td align='center' width='5%'><input type='checkbox' name='first_name' /></td>\
<td align='left'>"+<?php $row_dept->dept; ?>+"</td>\ /*If I remove this line, there is no error. But no value is shown*/
</tr>\
<?php }; ?>
<tr>\
<td colspan='2'><h3>Disposisi</h3>\<textarea id='disposisi' name='disposisi' class='form-control'></textarea></td>\
</tr>\
</table>\
</form>",
buttons : {
cancel : { label: '<i class="fa fa-times"></i> Batal' },
confirm : { label: '<i class="fa fa-check"></i> OK'}
},
callback: function (result) {
if(result == true){
var disposisi = $("#test").find('textarea[name=disposisi]').val();
alert(disposisi);
}
}
});
看来您有换行问题。
尝试一下-反引号`在较新的浏览器中有效-否则始终使用“ ...” +“ ...”
bootbox.confirm({ title: "Testing", message: `<form id='test'> <h3>Dept: </h3> <table width='100%' cellspacing='0' cellpadding='3px'> <?php foreach($dept as $row_dept){ ?> <tr> <td align='center' width='5%'><input type='checkbox' name='first_name' /></td>\\ <td align='left'><?php echo $row_dept->dept; ?></td> </tr> <?php }; ?> <tr> <td colspan='2'><h3>Disposisi</h3><textarea id='disposisi' name='disposisi' class='form-control'></textarea></td> </tr> </table> </form>`, buttons: { cancel: { label: '<i class="fa fa-times"></i> Batal' }, confirm: { label: '<i class="fa fa-check"></i> OK' } }, callback: function(result) { if (result == true) { var disposisi = $("#test").find('textarea[name=disposisi]').val(); alert(disposisi); } } });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.