x可编辑重置字段



我有以下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>

你能完成我的重置按钮脚本吗?目的是在点击后为cust_name和cust_addr分配null。。这是的脚本

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

这似乎奏效了。

http://jsfiddle.net/U33kT/

我不确定区别,只是我选择了所有可编辑的内容(JS第6行):

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

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

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

它似乎也起到了作用。

希望这能有所帮助。

最新更新