但是个人感觉没有那个必要,
对于js遍历java集合对象(list)的话,需要进行一些转化 *** 作,可以将java中的list对象中的数据通过
json-lib来转成json。如果再做处理<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>demo</title>
<style type="text/css">
table {
display: table;
border-collapse: collapse;
border: 1px solid #ccc;
}
tr, td, th {
border: 1px solid #ccc;
}
input {
min-width: 100px;
}
operator {
margin: 20px 0;
}
button {
background: white;
font-size: 16px;
}
tr, td, th, input, button {
padding: 6px 12px;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>名称</th>
<th>年龄</th>
<th>描述</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div class="operator">
<button type="button" name="add">设置</button>
<button type="button" name="get" disabled>获取</button>
</div>
</body>
<script type="text/javascript">
var $ = function (selector, context) {
return (context || document)querySelector(selector);
};
var $$ = function (selector, context) {
return (context || document)querySelectorAll(selector);
};
function createTd(name) {
var td = documentcreateElement('td');
var input = documentcreateElement('input');
inputsetAttribute('type', 'text');
inputsetAttribute('name', name);
inputsetAttribute('value', name + Mathfloor(Mathrandom() 100 + 1));
tdappendChild(input);
return td;
}
function addRows(len) {
var fg = documentcreateDocumentFragment();
while (len-- > 0) {
var tr = documentcreateElement('tr');
trappendChild(createTd('name'));
trappendChild(createTd('age'));
trappendChild(createTd('desc'));
fgappendChild(tr);
}
$('tbody')appendChild(fg);
}
function getRows() {
var rows = []slicecall($$('tbody>tr'));
return rowsmap(function (tr) {
return {
name: $('[name=name]', tr)value,
age : $('[name=age]', tr)value,
desc: $('[name=desc]', tr)value,
};
});
}
$('[name=add]')addEventListener('click', function () {
[]slicecall($$('tbody>tr'))forEach(function (tr) {
$('tbody')removeChild(tr);
});
addRows(10);
$('[name=get]')removeAttribute('disabled');
}, false);
$('[name=get]')addEventListener('click', function () {
consoletable(getRows());
}, false);
</script>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)