***综合类***在页面的列表中添加删除条目
把下列代码加到网页的<body></body>标签之间 从google下载我的照片管理软件要完成此效果需要三个步骤
第一步:把如下代码加入到<head>区域中
<script language="javascript">
<!-- begin
function small_window(myurl) {
var newwindow;
var props = 'scrollbars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,width=300,height=200';
newwindow = window.open(myurl, "add_from_src_to_dest", props);
}
function addtoparentlist(sourcelist) {
destinationlist = window.document.forms.parentlist;
for(var count = destinationlist.options.length - 1; count >= 0; count--) {
destinationlist.options = null;
}
for(var i = 0; i < sourcelist.options.length; i++) {
if (sourcelist.options != null)
destinationlist.options = new option(sourcelist.options.text, sourcelist.options.value );
}
}
// marks all the items as selected for the submit button.
function selectlist(sourcelist) {
sourcelist = window.document.forms.parentlist;
for(var i = 0; i < sourcelist.options.length; i++) {
if (sourcelist.options != null)
sourcelist.options.selected = true;
}
return true;
}
// deletes the selected items of supplied list.
function deleteselecteditemsfromlist(sourcelist) {
var maxcnt = sourcelist.options.length;
for(var i = maxcnt - 1; i >= 0; i--) {
if ((sourcelist.options != null) && (sourcelist.options.selected == true)) {
sourcelist.options = null;
}
}
}
//end -->
</script>
第二步:把如下代码加入到<body>区域中
<center>
<form method=post>
<table border=1 bgcolor="#ffffcc">
<tr>
<td>
<select size=5 name=parentlist multiple>
</select>
</td>
</tr>
<tr>
<td align=center>
<input type=button value="添加" onclick = "javascript:small_window('../zh/78-1.htm');">
<input type=button value="删除" onclick = "javascript:deleteselecteditemsfromlist(parentlist);">
</td>
</tr>
</table>
</form>
</center>
第三步:新建一个../zh/78-1.htm文件,把如下代码copy其中
<html>
<head>
<script language="javascript">
begin
<!--
// add the selected items in the parent by calling method of parent
function addselecteditemstoparent() {
self.opener.addtoparentlist(window.document.forms.destlist);
window.close();
}
// fill the selcted item list with the items already present in parent.
function fillinitialdestlist() {
var destlist = window.document.forms.destlist;
var srclist = self.opener.window.document.forms.parentlist;
for (var count = destlist.options.length - 1; count >= 0; count--) {
destlist.options = null;
}
for(var i = 0; i < srclist.options.length; i++) {
if (srclist.options != null)
destlist.options = new option(srclist.options.text);
}
}
// add the selected items from the source to destination list
function addsrctodestlist() {
destlist = window.document.forms.destlist;
srclist = window.document.forms.srclist;
var len = destlist.length;
for(var i = 0; i < srclist.length; i++) {
if ((srclist.options != null) && (srclist.options.selected)) {
//check if this value already exist in the destlist or not
//if not then add it otherwise do not add it.
var found = false;
for(var count = 0; count < len; count++) {
if (destlist.options != null) {
if (srclist.options.text == destlist.options.text) {
found = true;
break;
}
}
}
if (found != true) {
destlist.options = new option(srclist.options.text);
len++;
}
}
}
}
// deletes from the destination list.
function deletefromdestlist() {
var destlist= window.document.forms.destlist;
var len = destlist.options.length;
for(var i = (len-1); i >= 0; i--) {
if ((destlist.options != null) && (destlist.options.selected == true)) {
destlist.options = null;
}
}
}
// end -->
</script>
<title>typhoon start javascript fairyland</title></head>
<body onload="javascript:fillinitialdestlist();" bgcolor="#000000">
<center>
<form method="post">
<table bgcolor="#ffffcc">
<tr>
<td bgcolor="#ffffcc" width="74">可选区</td>
<td bgcolor="#ffffcc"> </td>
<td bgcolor="#ffffcc" width="69">已选区</td>
</tr>
<tr>
<td bgcolor="#ffffcc" width="85">
<select size="6" name="srclist" multiple>
<option value="1">item 1
<option value="2">item 2
<option value="3">item 3
<option value="4">item 4
<option value="5">item 5
<option value="6">item 6
</select>
</td>
<td bgcolor="#ffffcc" width="74" align="center">
<input type="button" value=" >> " onclick="javascript:addsrctodestlist()">
<br><br>
<input type="button" value=" << " onclick="javascript:deletefromdestlist();">
</td>
<td bgcolor="#ffffcc" width="69">
<select size="6" name="destlist" multiple>
</select>
</td>
</tr>
<tr>
<td colspan=3 align="center">
<input type="button" value="done" onclick = "javascript:addselecteditemstoparent()">
</td>
</tr>
</table>
</form>
</center></body>
</html>
---------- ----- -- - ------- ------- - -----
http://w ww.huoyue.com.cn 活跃网,活跃人群的论坛,访问活跃网,将给您带来意想不到的 收获,还可以免费为您开论坛,让您免费 拥有与朋友、网友交流 的 论坛。你是年轻 人吗?你活跃你就上!
页:
[1]