3

我有以下 html/php 代码(省略了 php 标签)

$user = array(
    'name' => Null,
    'address' => Null
);  

<div id="user">
    <a href="#"  id="cust_name" data-type="text"
         data-pk="'.$user['ag_id'].'" title="Enter customer name">'.$user['name'].'</a>
    <a href="#"  id="cust_addr" data-type="text"
         data-pk="'.$user['ag_id'].'" title="Enter customer address">'.$user['address'].'</a>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" id="ResetButton">Reset</button>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-primary" id="SaveButton"
             data-dismiss="modal">Save changes</button>
    </div>
</div>

您能否完成我的 resetbutton 脚本,目的是在单击后将 null 分配给 cust_name 和 cust_addr .. 这是脚本

<script>
    $.fn.editable.defaults.mode = 'inline';

    $(function(){
        $('#user a').editable({
           url: 'post.php' 
        });
    });

    $("#SaveButton").click(function() {
        $.ajax({
            url: 'db.php',
            type: 'POST',
            data: {}
        });
    });

    $('#ResetButton').click(function() {
        // $('#cust_name').editable('setValue', null); // did not worked            
        // didn't worked even i added class="myeditable" in my <a> tag
        /*
        $('.myeditable').editable('setValue', null)
           .editable('option', 'pk', null)
           .removeClass('editable-unsaved');
        */
    });

</script> 
4

1 回答 1

3

这似乎奏效了。

http://jsfiddle.net/U33kT/

我不确定有什么区别,除了我选择了所有可编辑项(JS 第 6 行):

$('#user a').editable('setValue', null);

但是,我尝试了单个项目:

$('#cust_name').editable('setValue', null);

它似乎也有效。

希望这可以帮助。

于 2014-01-22T22:22:54.457 回答