如何?如下功能

來源:互聯網
上載者:User
PHP代碼:--------------------------------------------------------------------------------
指令碼說明:
把如下代碼加入<body>地區中
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
oldvalue = "";
function passText(passedvalue) {
if (passedvalue != "") {
var totalvalue = passedvalue+"\n"+oldvalue;
document.displayform.itemsbox.value = totalvalue;
oldvalue = document.displayform.itemsbox.value;
}
}
// End -->
</script>
<form name="selectform">
<select name="dropdownbox" size=1>
<option value="">請選擇</option>
<option value="第一項">第一項</option>
<option value="第二項">第二項</option>
<option value="第三項">第三項</option>
<option value="第四項">第四項</option>
<option value="第五項">第五項</option>
<option value="第六項">第六項</option>
</select>
<input type=button value="添加到列表中" onClick="passText(this.form.dropdownbox.options[this.form.dropdownbox.selectedIndex].value);">
</form>
<form name="displayform" >
<font face="Arial, Helvetica, Sans Serif" size="3"><b>你可以自己選擇一下:</b></font><br>
<textarea cols="30" rows="5" name="itemsbox" >

PHP代碼:--------------------------------------------------------------------------------
指令碼說明:
把如下代碼加入<body>地區中
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var delimiter = ":";
function MoveOption (MoveFrom, MoveTo, ToDo) {
var SelectFrom = eval('document.main_form.'+MoveFrom);
var SelectTo = eval('document.main_form.'+MoveTo);
var SelectedIndex = SelectFrom.options.selectedIndex;
var container;
if (ToDo=='Add') {
container=eval('document.main_form.'+ToDo+MoveTo);
}
if (ToDo=='Remove') {
container=eval('document.main_form.'+ToDo+MoveFrom);
}
if (SelectedIndex == -1) {
alert("請選擇一個使用者");
} else {
for (i=0; i<SelectFrom.options.length; i++) {
if(SelectFrom.options[i].selected) {
var name = SelectFrom.options[i].text;
var ID = SelectFrom.options[i].value;
SelectFrom.options[i] = null;
SelectTo.options[SelectTo.options.length]=new Option (name,ID);
i=i-1;
if(ToDo=='Add'||ToDo=='Remove') {
container.value=container.value+name+delimiter;
//container.value=container.value+ID+delimiter;
}
}
}
}
}
function CheckDuplicates (AddListContainer, RemoveListContainer) {
var AddList = eval('document.main_form.'+AddListContainer);
var RemoveList = eval('document.main_form.'+RemoveListContainer);
var TempAddList = AddList.value;
var TempRemoveList = RemoveList.value;
if (TempAddList>''&&TempRemoveList>'') {
TempAddList = TempAddList.substring(0,TempAddList.length-1);
TempRemoveList = TempRemoveList.substring(0,TempRemoveList.length-1);
var AddArray = TempAddList.split(delimiter);
var RemoveArray = TempRemoveList.split(delimiter);
for (i=0; i<AddArray.length; i++) {
for (j=0; j<RemoveArray.length; j++) {
if (AddArray[i]==RemoveArray[j]) {
AddArray[i]='';
RemoveArray[j]='';
break;
}
}
}
AddList.value='';
for (i=0; i<AddArray.length; i++) {
if (AddArray[i]>'') {
AddList.value = AddList.value + AddArray[i] + delimiter;
}
}
RemoveList.value='';
for (i=0; i<RemoveArray.length; i++) {
if (RemoveArray[i]>'') {
RemoveList.value = RemoveList.value + RemoveArray[i] + delimiter;
}
}
}
}
function LockChanges() {
CheckDuplicates('AddAdmins','RemoveAdmins');
CheckDuplicates('AddUsers','RemoveUsers');
}
// End -->
</script>
<table align="center">
<tr><td>
<FORM name=main_form action="" method=post><INPUT type=hidden name=AddAdmins>
<INPUT type=hidden name=RemoveAdmins> <INPUT type=hidden name=AddUsers> <INPUT
type=hidden name=RemoveUsers>
<div align="center">
<table cellspacing="0" cellpadding="5" border="0">
<tbody>
<tr>
<td valign="top" align="middle" rowspan="2">備選使用者<br><select multiple size="12" name="Employees">
<option>Employee_01<option>Employee_02<option>Employee_03<option>Employee_04<option>Employee_05<option>Employee_06<option>Employee_07<option>Employee_08<option>Employee_09<option>Employee_10</option></select>
</td>
<td>
<p align="center"><input onclick="MoveOption('Employees','Admins','Add');" type="button" value="增加Admin >>" name=add_admin>
</p>
<p align="center"><input onclick="MoveOption('Admins','Employees','Remove');" type="button" value="<< 刪除Admin" name="remove_admin">
</p></td>
<td valign="top" align="middle">Administrators<br><select multiple size="5" name="Admins">
<option>Admin_01<option>Admin_02<option>Admin_03<option>Admin_04<option>Admin_05</option></select>
</td></tr>
<tr>
<td>
<p align="center"><input onclick="MoveOption('Employees','Users','Add');" type="button" value="增加User >> " name=add_user>
</p>
<p align="center"><input onclick="MoveOption('Users','Employees','Remove');" type="button" value=" << 刪除User " name="remove_user">
</p></td>
<td valign="top" align="middle">Users<br><select multiple size="5" name="Users">
<option>User_01<option>User_02<option>User_03<option>User_04<option>User_05</option></select>
</td></tr>
</tbody>
</table>
</div>
</FORM>
</td></tr>
<tr><td>
<div align="center"><input onclick="LockChanges();" type="button" value="儲存修改"></div>
<BR>
<div align="center">
<a href="java script:alert(document.main_form.AddAdmins.value);">查詢增加的Admin</a>
<br>
<a href="java script:alert(document.main_form.RemoveAdmins.value);">查詢刪除的Admin</a>
<br>
<a href="java script:alert(document.main_form.AddUsers.value);">查詢增加的User</a>
<br>
<a href="java script:alert(document.main_form.RemoveUsers.value);">查詢刪除的User</a>
</div>
</td></tr>
</td></tr>
</table>


PHP代碼:--------------------------------------------------------------------------------
指令碼說明:
把如下代碼加入<body>地區中:
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
sortitems = 1; // Automatically sort items within lists? (1 or 0)

function move(fbox,tbox) {
for(var i=0; i<fbox.options.length; i++) {
if(fbox.options[i].selected && fbox.options[i].value != "") {
var no = new Option();
no.value = fbox.options[i].value;
no.text = fbox.options[i].text;
tbox.options[tbox.options.length] = no;
fbox.options[i].value = "";
fbox.options[i].text = "";
}
}
BumpUp(fbox);
if (sortitems) SortD(tbox);
}
function BumpUp(box) {
for(var i=0; i<box.options.length; i++) {
if(box.options[i].value == "") {
for(var j=i; j<box.options.length-1; j++) {
box.options[j].value = box.options[j+1].value;
box.options[j].text = box.options[j+1].text;
}
var ln = i;
break;
}
}
if(ln < box.options.length) {
box.options.length -= 1;
BumpUp(box);
}
}

function SortD(box) {
var temp_opts = new Array();
var temp = new Object();
for(var i=0; i<box.options.length; i++) {
temp_opts[i] = box.options[i];
}
for(var x=0; x<temp_opts.length-1; x++) {
for(var y=(x+1); y<temp_opts.length; y++) {
if(temp_opts[x].text > temp_opts[y].text) {
temp = temp_opts[x].text;
temp_opts[x].text = temp_opts[y].text;
temp_opts[y].text = temp;
temp = temp_opts[x].value;
temp_opts[x].value = temp_opts[y].value;
temp_opts[y].value = temp;
}
}
}
for(var i=0; i<box.options.length; i++) {
box.options[i].value = temp_opts[i].value;
box.options[i].text = temp_opts[i].text;
}
}
// End -->
</script>

<form ACTION="" METHOD="POST">
<table border="0">
<tr>
<td><select multiple size="5" name="list1">
<option value="11"> item 1.1 </option>
<option value="12"> item 1.2 </option>
<option value="13"> item 1.3 </option>
</select></td>
<td>
<input type="button" value=" >> " onclick="move(this.form.list1,this.form.list2)" name="B1"><br>
<input type="button" value=" << " onclick="move(this.form.list2,this.form.list1)" name="B2">
</td>
<td><select multiple size="5" name="list2">
<option value="21"> item 2.1 </option>
<option value="22"> item 2.2 </option>
<option value="23"> item 2.3 </option>
</select></td>
</tr>
</table>
</form>


相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。