x可编辑值更改动态不起作用

时间:2014-09-26 04:21:56

标签: jquery twitter-bootstrap x-editable

我已经通过bootstrap应用程序使用x可编辑文件。现在我有一种情况,我需要通过按钮click.value更改我的跨度值,但如果我点击该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>

此处城市范围首先填充'初始值',当我点击该范围时,文本框将显示值'初始值',然后如果我点击更改按钮,则范围值将更改为'更改值'。然后,如果我再次点击跨度文本框显示前一个值'初始值'。如何解决此问题任何帮助将不胜感激

这是jfiddle链接jfiddle

2 个答案:

答案 0 :(得分:25)

要为x可编辑对象设置新值,您必须调用其方法setValue

Documentation Here

演示:JSFiddle

示例:

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

答案 1 :(得分:1)

这是您的解决方案。您只需要在更改按钮点击时设置值。您只需要在“#change&#39;”中添加此行$('#city').editable('setValue', "changed value", true);即可。按钮的点击。有关更多详细信息,请参阅我的jsfiddle代码:http://jsfiddle.net/smvora_4u/epf7frz4/