2014-09-26 58 views
6

我已經使用x可編輯文件由引導應用程序。現在我有一種情況,我需要通過按鈕click.value改變我的跨度的值,但如果我點擊那個x可編輯範圍,以前的值填充在文本框 這是我的示例代碼x可編輯的值變化動態不工作

<head> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> 
    <meta charset="utf-8" /> 
    <title>Patient portal</title> 
      <meta name="description" content="3 styles with inline editable feature" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> 
      <link rel="stylesheet" href="assets/css/bootstrap-editable.css" /> 

</head> 

<body ><!-- #section:basics/navbar.layout --> 
     <div> 
       <span class="editable" id="city"> intial value </span> 
       <button id="change">change value</button> 

     </div> 
      <script type="text/javascript"> 
     window.jQuery || document.write("<script src='assets/js/jquery.min.js'>"+"<"+"/script>"); 
    </script> 
    <script src="assets/js/bootstrap.min.js"></script> 
      <script src="assets/js/x-editable/bootstrap-editable.min.js"></script> 
    <script src="assets/js/x-editable/ace-editable.min.js"></script> 

    <!-- inline scripts related to this page --> 

    <script type="text/javascript"> 
    $(document).ready(function() { 
     $.fn.editable.defaults.mode = 'inline'; 
     $.fn.editableform.loading = "<div class='editableform-loading'><i class='ace-icon fa fa-spinner fa-spin fa-2x light-blue'></i></div>"; 
    $.fn.editableform.buttons = '<button type="submit" class="btn btn-info editable-submit"><i class="ace-icon fa fa-check"></i></button>'+ 
             '<button type="button" class="btn editable-cancel"><i class="ace-icon fa fa-times"></i></button>'; 
    $('#city').editable({ 
      type: 'text', 
      name: 'FirstName', 
      title: 'enter First Name', 
      validate: function(value) { 
       if($.trim(value) == '') 
        return ' First Name is required'; 
       else if($.trim(value).length>30) 
        return 'Only 50 charateres are allowed'; 
       } 

     }); 



     $('#change').click(function(){ 
      $('#city').text("changed value") 
     }); 

    }) 

    </script> 

</body> 

這裏城市跨度填充「初值」第一,當我點擊跨度的文本框將值「初值」出現,那麼如果我點擊更改按鈕跨度值將更改爲「更改的值」。然後,如果再次單擊跨度文本框是s howing先前值「初值」。怎麼能解決這個問題的任何幫助將不勝感激

這是jfiddle鏈接jfiddle

+0

你能撥弄嗎? – divakar 2014-09-26 04:25:30

+0

@divakar我添加了jfiddle鏈接 – abhi 2014-09-26 04:40:38

回答

21

對於一個新的值設置爲一個X可編輯的對象,你必須調用它方法setValue

Documentation Here

演示:JSFiddle

例子:

$('#change').click(function(){ 
     $('#city').editable('setValue',"changed value"); 
    }); 
1

這裏是您的解決方案。你只需要做的就是改變按鈕點擊設置值。您只需在'#change'按鈕的點擊中添加此行$('#city').editable('setValue', "changed value", true);。欲瞭解更多詳情,請參閱我的jsfiddle代碼:http://jsfiddle.net/smvora_4u/epf7frz4/