如果有人能帮助我找到解决一个问题的方法,我将不胜感激,我的创建表单中有一个复选框。如果我按下创建按钮,我希望在选中复选框时有一个弹出窗口,如果复选框未选中,则什么也不做。
这是我开始的。
<?php echo $form->checkBoxRow($model, 'default'); ?>
<div class="form-actions">
<?php $this->widget('bootstrap.widgets.TbButton', array(
'buttonType'=>'submit',
'type'=>'primary',
'label'=>$model->isNewRecord ? 'Create' : 'Save',
)); ?>
</div>
请帮我解决这个问题
使用它来检查复选框是否被选中
$('#create').click(function(){
if ($('#checkbox').is(':checked')) {
//Show your dialog over here
}
});
它会很长,所以我没有在comentary中发帖。要实现您想要的,您实际上不需要按钮。您可以将其设置为链接,甚至是一些容器,只需应用样式即可。所以从代码开始:
<?php echo $form->checkBoxRow($model, 'default'); ?>
<div class="form-actions">
//some div or link here - doesnt matter, lets call it #sub_button
</div>
现在将js添加到您的div(链接),在html或绑定中单击文档就绪。
<div id="sub_button" onclick=getModal()>
<?php
if ($model->isNewRecord) echo 'Create' ;
else echo 'Save'
?>
</div>
现在编写你的getModal()函数:
function getModal(){
if (($('#default').prop("checked")){
//show here your dialog or modal window
//if you need to pass some data or render it - use ajax
//$().dialog() if its simple jui
}
else {}//show some notification or what you want here
}
还有 1 个 - 不要将 js 与 php 混合使用。你不能在js中使用php,为此存在ajax。你唯一能做的 - 将 php 值回显到 js 变量。此外,您不能将js变量传递给php,只能通过ajax。