首先B页面创建的时候,当生成记录时,可以再开头放置图片用来点击执行事件:
<tr id="bus<%= rowIndex %>">
<td class="busTableIcon"><input type="hidden" name="objectId" value="<%= busListState.getRowBusId() %>"><img src="../../aa.bmp" id="bus<%= rowIndex %>" onClick="clickObject('bus<%= rowIndex %>', '<%= busListState.getRowBusId() %>')" alt=""></td>
<td> cell 1</td>
<td> cell 2</td>
<td> cell 3</td>
.....
</tr>
JS:
function clickObject(objectNo, objectId) {
objects = businessObjects;
var object = objects[objectNo];
if (object == null) {
object = new Object(objectId);
objects[objectNo] = object;
}
object.checked = !object.checked;
if (object.checked) {
//onBorder(objectNo, 3);
changeOnStyle(objectNo);
} else {
//onBorder(objectNo, 0);
changeOffStyle(objectNo);
}
} 其中businessObjects,objects object需要在页面开始定义:
var objects;
var businessObjects = new Array();
function Object(id) {
this.name = "ids";
this.value = id;
this.checked = false;
}
其中改变整条记录颜色如下:
function changeOnStyle(objectNo) {
applyStyle(objectNo, "#99FF99");
}
function changeOffStyle(objectNo) {
applyStyle(objectNo, "#FFFFFF");
}
function applyStyle(objectNo, appliedStyle) {
if(document.getElementById){document.getElementById(objectNo).style.backgroundColor=appliedStyle}
}
点击过的记录保存在businessObjects中,下边在提供一个,A页面需要调用B页面的方法
function getSelectedBOs() {
var arrObjs = new Array();
var arrIndex = 0;
for (var bus in businessObjects) {
if (businessObjects[bus].checked) {
arrObjs[arrIndex] = businessObjects[bus];
arrIndex++;
}
}
return arrObjs;
}
从中可以看到javaScript中
改变objects实际上是在修改businessObjects, 还可以这样用for (var bus in businessObjects) {
javaScript基础不好的同志们可以找本书看看,对于页面开发很有帮助的。