html5 contenteditable 实现table可编辑(网页版EXCEL)
生活随笔
收集整理的這篇文章主要介紹了
html5 contenteditable 实现table可编辑(网页版EXCEL)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一直想找一個(gè)免費(fèi)的網(wǎng)頁(yè)版的EXCEL插件,以便于多人共同在線(xiàn)編輯,始終沒(méi)發(fā)現(xiàn)合適的。
其實(shí)自己實(shí)現(xiàn)類(lèi)似功能也不難。參考:https://blog.csdn.net/chadcao/article/details/52014730
直接將以下代碼存在本地目錄中,如A.html,雙擊在瀏覽器中打開(kāi),即可對(duì) 姓名 字段進(jìn)行編輯。
<!doctype html>
<html>
<head>
<title>table contenteditable</title>
<script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
var students = [
{ 'no': 'S001', 'name': '張三', 'address': '浙江' },
{ 'no': 'S002', 'name': '李四', 'address': '江蘇' },
{ 'no': 'S003', 'name': '王五', 'address': '福建' },
{ 'no': 'S004', 'name': '馬六', 'address': '四川' }
];
$(function () {
InitStudents();
});
function InitStudents() {
var html = '';
$.each(students, function (i, item) {
html += '<tr>';
html += '<td>' + item.no + '</td>';
html += '<td><span contenteditable="true" class="studentname">' + item.name + '</span></td>';
html += '<td>' + item.address + '</td>';
html += '</tr>';
});
$('#mainTbody').append(html);
}
function GetStudents() {
var studentnames = '';
$('#mainTbody span.studentname').each(function () {
studentnames += '【' + $(this).text() + '】';
});
alert(studentnames);
}
</script>
</head>
<body>
<div><input type="button" value="確定" onclick="GetStudents();" /></div>
<div>
<table>
<thead>
<tr>
<td>學(xué)號(hào)</td>
<td>姓名</td>
<td>地址</td>
</tr>
</thead>
<tbody id="mainTbody"></tbody>
</table>
</div>
</body>
</html>
總結(jié)
以上是生活随笔為你收集整理的html5 contenteditable 实现table可编辑(网页版EXCEL)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 如何基于ERP的sales organi
- 下一篇: X3C to X9T