yii2 自定义引导框模式而不是在数据确认时发出警报
yii2 customize a bootbox modal instead of alert on data-confirm
例如,我想更改 bootbox.alert(...
'delete' => function ($url, $model, $key) {
return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
'title' => Yii::t('yii', 'Delete'),
'class'=>'btn btn-primary',
'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
'data-method' => 'post',
'data-pjax' => '0',
]);
},
只需指定一个 class 名称或 ID 即可:"id"=>"btn-id"
然后覆盖点击事件:
$("#btn-id").on("click",function(e){
e.preventDefault();
//Somethings and return here
}));
只需向元素添加 HTML class,删除 "data-confirm" 参数并使用 "click" 事件。
这样你就可以在点击 link 时执行任何你想执行的操作。
'delete' => function ($url, $model, $key) {
return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
'title' => Yii::t('yii', 'Delete'),
'class'=>'btn btn-primary delete-button',
'data-id' => $model->id, // For using when the button is clicked
]);
},
在你的 javascript 文件中:
$(".delete-button").on("click",function(e){
e.preventDefault();
var modelId = $(this).data('id');
// Run bootbox.alert() here!!
// Based on the bootbox result, you can decide to fire the initial event again:
// $(this).unbind('submit').submit()
});
希望对您有所帮助:)
Link 覆盖 yii.js 确认 --> bootbox.confirm.
例如,我想更改 bootbox.alert(...
'delete' => function ($url, $model, $key) {
return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
'title' => Yii::t('yii', 'Delete'),
'class'=>'btn btn-primary',
'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
'data-method' => 'post',
'data-pjax' => '0',
]);
},
只需指定一个 class 名称或 ID 即可:"id"=>"btn-id" 然后覆盖点击事件:
$("#btn-id").on("click",function(e){
e.preventDefault();
//Somethings and return here
}));
只需向元素添加 HTML class,删除 "data-confirm" 参数并使用 "click" 事件。 这样你就可以在点击 link 时执行任何你想执行的操作。
'delete' => function ($url, $model, $key) {
return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
'title' => Yii::t('yii', 'Delete'),
'class'=>'btn btn-primary delete-button',
'data-id' => $model->id, // For using when the button is clicked
]);
},
在你的 javascript 文件中:
$(".delete-button").on("click",function(e){
e.preventDefault();
var modelId = $(this).data('id');
// Run bootbox.alert() here!!
// Based on the bootbox result, you can decide to fire the initial event again:
// $(this).unbind('submit').submit()
});
希望对您有所帮助:)
Link 覆盖 yii.js 确认 --> bootbox.confirm.