1.介绍
x-editable用于即时编辑网页文本,界面美观,非常好用。
x-editable官网:http://vitalets.github.io/x-editable/
x-editable学习推荐网站:http://www.cnblogs.com/landeanfen/p/5821192.html
使用x-editable首先需要在官网下载js和css。
其样式如下:
2.使用小结
需要bootstrap-editable.css和bootstrap-editable.min.js,好像依赖jquery和bootstrap。
html如下:
<a href="#" id="username">superuser</a>
$(document).ready(function() {
$('#username').editable();
});
$("#username").editable('setValue', value)
$("#username").editable('setValue', null).removeClass('editable-unsaved');
var username = $("#username").editable('getValue', true);
$('#username').editable({
type : 'text',
placeholder: '请输入用户名',
url : function(params) {
return $.post(...);
},
validate : function(value) {
if (value == '') {
return '不能为空';
}
}
});
通过params.value可以拿到文本框中的值。