我有一些使头部感到沉重的问题...我在该论坛中搜索了答案,但问题仍然没有解决。
我的问题是我有一个链接到模态的按钮。当页面刷新后第一次单击按钮时,模式打开。但不是第二次。
我已经检查了日志,日志说
TypeError: $(...).modal is not a function[Learn More].
如果我刷新页面,它将只工作一次,并且第二次单击按钮,模态不会再次打开...
这是我的按钮HTML查看代码。
<button class="btn btn-info btn-sm btn-labeled" type="button" id="tambahUser" data-toggle = "modal" value="<?= Url::to(['/module/create'],true)?>">
这是我的情态
<div id="modalSignUpSm" tabindex="-1" role="dialog" class="modal fade">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header bg-info">
<button type="button" class="close" data-dismiss="modal" id="tutupModal">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<h4 class="modal-title">Colored Header Modal</h4>
</div>
<div class="modal-body">
<div id="modalContent"></div>
</div>
</div>
</div>
</div>
这是我的js代码,负责处理按钮的click事件
$('#tambahUser').click(function(event){
$('#modalSignUpSm').modal({
backdrop: 'static',
keyboard: false,
})
.modal('show')
.find('#modalContent')
.load($(this).attr('value'));
});
$('#tutupModal').click(function(){
$('#modalSignUpSm').modal('close');
});
这是我的Module / create的控制器(我正在使用Yii2)
public function actionCreate()
{
$model = new Module();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(Url::to(['/paneladm/pengaturan/module',true]));
} else {
return $this->renderAjax('create', [
'model' => $model,
]);
}
}
我的问题是为什么模态只打开一次,然后按钮被卡住..?如何解决...
注意:-我是jQuery的新手,对于每个答案我都将非常感谢。
-我在这个论坛上搜索并尝试创建一个按钮来解决该问题,每点击此按钮将触发.modal('close')但仍然无法正常工作
最佳答案
您应该使用Bootstraps数据属性来触发模式的开和关,或者通过javascript手动使用触发。现在,您正在尝试同时执行这两项操作。请参见this example。
因此,我将删除引导程序数据属性,然后确保在您自己的JavaScript之前加载了引导程序脚本。