我正在尝试将JQuery插件附加到JQuery模板。除了将处理程序附加到此插件的confirm
和cancel
事件之外,我几乎已经弄明白了。
该插件来自此处:https://myclabs.github.io/jquery.confirm/
工作代码:
<script id="buttonsTemplate" type="text/x-jquery-tmpl">
<div class="col-md-6">
<button type="button" id="enterInPTPButton" class="btn btn-primary" style="border-radius: 0; margin-left:10px; border-color:#3C5B75;">Entered In PTP</button>
<button type="button" id=${'deleteEntryButton' + rowName} class="btn btn-warning confirm" style="border-radius: 0; margin-left:10px;">Delete Entry</button>
<button type="button" id="offboardedButtons" class="btn btn-info" style="border-radius: 0; margin-left:10px; border-color:#3A7B8E;">Offboarded</button>
</div>
<script type="text/javascript">
var rowName = "#deleteEntryButton";
rowName = ${rowName};
$(rowName).confirm({
text: "Are you sure you want to delete this entry?",
title: "Confirmation Required",
confirmButton: "Yes I am",
cancelButton: "No",
confirmButtonClass: "btn-danger",
cancelButtonClass: "btn-default"
});
{{html "</sc"+"ript>"}}
</script>
非工作代码:
<script id="buttonsTemplate" type="text/x-jquery-tmpl">
<div class="col-md-6">
<button type="button" id="enterInPTPButton" class="btn btn-primary" style="border-radius: 0; margin-left:10px; border-color:#3C5B75;">Entered In PTP</button>
<button type="button" id=${'deleteEntryButton' + rowName} class="btn btn-warning confirm" style="border-radius: 0; margin-left:10px;">Delete Entry</button>
<button type="button" id="offboardedButtons" class="btn btn-info" style="border-radius: 0; margin-left:10px; border-color:#3A7B8E;">Offboarded</button>
</div>
<script type="text/javascript">
var rowName = "#deleteEntryButton";
rowName = ${rowName};
$(rowName).confirm({
text: "Are you sure you want to delete this entry?",
title: "Confirmation Required",
confirm: function(button) {
DeleteEntry();
},
cancel: function(button) {
// nothing to do
},
confirmButton: "Yes I am",
cancelButton: "No",
confirmButtonClass: "btn-danger",
cancelButtonClass: "btn-default"
});
{{html "</sc"+"ript>"}}
</script>
一旦我添加以下内容,它就会停止工作:
confirm: function(button) {
DeleteEntry();
},
cancel: function(button) {
// nothing to do
},
这段代码似乎确实适用于静态元素。造成这种情况的原因是什么,我该怎么做才能解决这个问题?
编辑:这是控制台中的完整错误:
Uncaught SyntaxError:inputn.extend.globalEval @的意外结束 jquery.js:328n.fn.extend.domManip @ jquery.js:5435jQuery.fn.extend.domManip @ jquery.tmpl.js:105n.fn.extend.append @ jquery.js:5218jQuery.fn。(匿名函数)@ jquery.tmpl.js:60FillTables @ userCodeAppPanel:119(匿名函数) @ userCodeAppPanel:49ri @ 348032839-mae_html_user_bin_i18n_mae_html_user.js:49(匿名 功能)@ 348032839-mae_html_user_bin_i18n_mae_html_user.js:14Cj.v @ 348032839-mae_html_user_bin_i18n_mae_html_user.js:75ph @ 348032839-mae_html_user_bin_i18n_mae_html_user.js:30kh @ 348032839-mae_html_user_bin_i18n_mae_html_user.js:31(匿名 功能)@ 348032839-mae_html_user_bin_i18n_mae_html_user.js:28