x-editable 的使用方法

时间:2023-03-09 16:32:46
x-editable 的使用方法

1.首先在html网页中定义一个a标签(如下<%#%>是asp.net的语法)

  <a href="#"  data-pk="<%#Eval("id")%>" data-url="FuncKeyEdit.ashx?opera=1" class="test">x-editable测试</a>

  解释

     1.data-pk 是数据库记录的主键

       2. data-url 是处理提交的url

2.js调用写法

  

<script>
  $.fn.editable.defaults.mode = 'inline';
  $('.test').editable({
    type: 'text',
    success: function (result, newValue) {
      if (result == "success") {
      layer.alert('修改成功', { icon: 1 });
      } else {
      layer.alert('修改失败', { icon: 2 });
    }

    }
  });
</script>

另外一种写法是把pk和url 写在参数里面,  另外需要注意的是在editable 内部不能够获取到当前元素的值或者属性

$('.test').editable({
    type: 'text',

    pk: '1',

    url:'/post',
    success: function (result, newValue) {
      if (result == "success") {
      layer.alert('修改成功', { icon: 1 });
      } else {
      layer.alert('修改失败', { icon: 2 });
    }

    }
  });