[英]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.