【问题标题】:Popup a window if checkbox is checked in Yii如果在 Yii 中选中复选框,则弹出一个窗口
【发布时间】:2013-09-12 14:50:43
【问题描述】:

如果有人可以帮助我找到解决问题的方法,我将不胜感激,我的创建表单中有一个复选框。如果我按下创建按钮,如果复选框被选中,我希望有一个弹出窗口,如果复选框未被选中,则不执行任何操作。

这是我开始的。

<?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>

请帮帮我

【问题讨论】:

  • 你想使用 jQuery 还是 Yii ?到目前为止你尝试过什么?
  • 我以不同的方式进行了尝试。我将弹出窗口放在我的创建按钮中。并将我的创建放在弹出窗口中。但这没有意义。

标签: php javascript jquery checkbox yii


【解决方案1】:

这会很长,所以我没有发表评论。要实现您想要的,您实际上并不需要按钮。您可以将其作为链接,甚至是一些容器,只需应用样式即可。 所以从代码开始:

<?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。

【讨论】:

    【解决方案2】:

    使用它来检查复选框是否被选中

    $('#create').click(function(){
        if ($('#checkbox').is(':checked')) {
            //Show your dialog over here
        }
    });
    

    【讨论】:

    • $("#myCheckbox").prop("checked");
    • 喜欢这个先生吗? checkBoxRow($model, 'default'); ?>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-24
    • 2022-11-27
    • 1970-01-01
    • 2017-11-22
    • 1970-01-01
    相关资源
    最近更新 更多