// html代码
<?= Html::a(
'删除',
[
'delete',
'id' => $id,
],
[
'data' => [
'confirm' => '你确定要删除吗?',
'method' => 'post',
],
]
)
?>
// html代码
window.yii = (function ($) {
var pub = {
// 定义了处理事件的方法,比如下面这个:
confirm: function (message, ok, cancel) {
if (window.confirm(message)) {
!ok || ok();
} else {
!cancel || cancel();
}
},
handleAction: function ($e, event) {
var $form = $e.attr('data-form') ? $('#' + $e.attr('data-form')) : $e.closest('form'),
method = !$e.data('method') && $form ? $form.attr('method') : $e.data('method'),
// 其他省略
},
// 其他省略
};
// 初始化模块
initModule: function (module) {
if (module.isActive !== undefined && !module.isActive) {
return;
}
if ($.isFunction(module.init)) {
module.init();
}
$.each(module, function () {
if ($.isPlainObject(this)) {
pub.initModule(this);
}
});
},
// 初始化方法
init: function () {
initCsrfHandler();
initRedirectHandler();
initAssetFilters();
initDataMethods();
},
return pub;
})(window.jQuery);
window.jQuery(function () {
window.yii.initModule(window.yii);
});
function initDataMethods() {
var handler = function (event) {
var $this = $(this),
method = $this.data('method'),
message = $this.data('confirm'),
form = $this.data('form');
if (method === undefined && message === undefined && form === undefined) {
return true;
}
if (message !== undefined) {
$.proxy(pub.confirm, this)(message, function () {
pub.handleAction($this, event);
});
} else {
pub.handleAction($this, event);
}
event.stopImmediatePropagation();
return false;
};
// handle data-confirm and data-method for clickable and changeable elements
$(document).on('click.yii', pub.clickableSelector, handler)
.on('change.yii', pub.changeableSelector, handler);
}
// 其他省略
$form = $('<form/>', {method: method, action: action});
var target = $e.attr('target');
if (target) {
$form.attr('target', target);
}
if (!/(get|post)/i.test(method)) {
$form.append($('<input/>', {name: '_method', value: method, type: 'hidden'}));
method = 'post';
$form.attr('method', method);
}
if (/post/i.test(method)) {
var csrfParam = pub.getCsrfParam();
if (csrfParam) {
$form.append($('<input/>', {name: csrfParam, value: pub.getCsrfToken(), type: 'hidden'}));
}
}
$form.hide().appendTo('body');
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有