请帮助我解决我的问题,我的问题是我创建了一个表,其中包含项目信息以及ADD,EDIT和DELETE。例如,如果我单击“添加”按钮,它将弹出一个对话框,其中包含来自其他页面的PHP表单。我使用了load()函数。
表单内有我的文本框,等等。下面是“确定”和“取消”按钮。但是,当我单击“取消”时,它不会关闭对话框。我尝试了不同的方法,但没有一个起作用。

这是我在“查看”部分中的代码(我正在使用Codeigniter)

 my button for add
 <input class="classname1"  type="button" value="ADD" name="add_item"/>
 .
 .
 .
 my div tag
 <div id="popup" style="display: none;"></div>
 .
 .
 .
 my jquery function

    /* FOR ADD PAGE */

    $(".hero-unit input[name=add_item]").on('click',function(){
        $('#popup').load("<?php echo site_url("item_controller/addNewItem/"); ?>").dialog({
            title: "Add New Item",
            autoOpen: true,
            width: 450,
            modal:true,
            open: function (event, ui) { window.setTimeout(function () {
                jQuery(document).unbind('mousedown.dialog-overlay').unbind('mouseup.dialog-overlay'); }, 100);
            },
            //if i include the close function it doesn't closing

        });
    });


单击按钮后的我的表单

<div>
  <?php $attr = array('class'=>'form-signin','id'=>'addForm'); ?>
  <?php echo form_open('item_controller/insertNewItem',$attr); ?>

    <h2 class="form-signin-heading"></h2>
        <h5 style="font-weight: normal;">Category Name</h5>
        <?php
            echo "<select name='categoryname' required='required'  autofocus='autofocus' >";
                echo "<option value=''>----------</option>";
                    foreach($category as $row){
                        echo "<option value='{$row['salescatname']}'>{$row['salescatname']}</option>";
                    }
            echo "</select>";
        ?>

        <h5 style="font-weight: normal;">Brand</h5>
        <input type="text" class="input-block-level" placeholder="Item Brand" required="required" name="brand" value="<?php echo set_value('description'); ?>" />
            <label style="color: red;"><?php echo form_error('brand'); ?></label>


        <h5 style="font-weight: normal;">Name</h5>
        <input type="text" class="input-block-level" placeholder="Item Name" required="required" name="name" value="<?php echo set_value('description'); ?>" />
            <label style="color: red;"><?php echo form_error('name'); ?></label>

        <h5 style="font-weight: normal;">Description</h5>
        <input type="text" class="input-block-level" placeholder="Description" required="required" name="description" value="<?php echo set_value('description'); ?>" />
            <label style="color: red;"><?php echo form_error('description'); ?></label>

        <h5 style="font-weight: normal;">Unit</h5>
        <input type="text" class="input-block-level" size="10" placeholder="Item Unit" required="required" name="unit" value="<?php echo set_value('description'); ?>" />
            <label style="color: red;"><?php echo form_error('unit'); ?></label>


        <h5 style="font-weight: normal;">Code:</h5>
        <input type="text" class="input-block-level" placeholder="Item Code" required="required" name="code" value="<?php echo set_value('name'); ?>"/>
            <label style="color: red;"><?php echo form_error('code'); ?></label>

        <br />
        <div align="right">
            <input type="submit" value="OK" class="btn btn-large btn-primary" />
            <input type="button" value="CANCEL" class="btn btn-large btn-primary" name='cancel' />//HERE'S THE BUTTON CANCEL. WHAT SHOULD I DO TO CLOSE THIS DIALOG?

        </div>
  <?php echo form_close(); ?>




所有人都希望您能帮助我。谢谢。

最佳答案

jQuery对话框具有一种提供内置按钮的机制。您不需要在您的php文件中手动添加它们。只需在您的对话框中添加一个按钮属性即可:

    buttons: {
        Ok: function() {
          // submit your form here
          $( this ).dialog( "close" );
        },
        Cancel: function() {
          // close handler
          $( this ).dialog( "close" );
        }
      }


这是一个“关闭”功能正常工作的例子:http://jsfiddle.net/ccamarat/E6ej9/5/

07-24 09:49
查看更多