两个listbox左右互相移动值的问题 就是执行左右移动的时候判断移动的值是否在listbox中存在 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 当选中listbox1里的1同时按下>>按钮,listbox1的值就变成2,3 那么如何再选中listbox1里的1? listbox我是靠一个下拉列表里的值做条件来绑定数据的~listbox1里的数据是绑定数据库里的数据 遍历listbox2.options查值试试看了for(var i=0;i<document.listbox2.options.length;i++){ if (xxxx == document.listbox2.options[i].value){ alert();return false; }} <html><head><link rel="stylesheet" href="../../css/xpc.css" type="text/css"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>ecVision XpressCommerce</title><script language="javascript" srccccccc="../../js/CommonJS_SwapOption.js">function moveLeftOrRight(fromObj,toObj) { var fromObjOptions=fromObj.options; for(var i=0;i<fromObjOptions.length;i++){ if(fromObjOptions[i].selected){ toObj.appendChild(fromObjOptions[i]); i--; } } resetAutoWidth(fromObj); resetAutoWidth(toObj);} function moveLeftOrRightAll(fromObj,toObj) { var fromObjOptions=fromObj.options; if(fromObjOptions.length>1000) { //if(!confirm("Are you sure to move options?")) return false; } for(var i=0;i<fromObjOptions.length;i++){ fromObjOptions[0].selected=true; toObj.appendChild(fromObjOptions[i]); i--; } resetAutoWidth(fromObj); resetAutoWidth(toObj);} function moveUp(selectObj) { var theObjOptions=selectObj.options; for(var i=1;i<theObjOptions.length;i++) { if( theObjOptions[i].selected && !theObjOptions[i-1].selected ) { swapOptionProperties(theObjOptions[i],theObjOptions[i-1]); } } selectObj.focus();//For a bug of IE7} function moveDown(selectObj) { var theObjOptions=selectObj.options; for(var i=theObjOptions.length-2;i>-1;i--) { if( theObjOptions[i].selected && !theObjOptions[i+1].selected ) { swapOptionProperties(theObjOptions[i],theObjOptions[i+1]); } } selectObj.focus();//For a bug of IE7} function moveToTop(selectObj){ var theObjOptions=selectObj.options; var oOption=null; for(var i=0;i<theObjOptions.length;i++) { if( theObjOptions[i].selected && oOption) { selectObj.insertBefore(theObjOptions[i],oOption); } else if(!oOption && !theObjOptions[i].selected) { oOption=theObjOptions[i]; } } selectObj.focus();//For a bug of IE7}function moveToBottom(selectObj){ var theObjOptions=selectObj.options; var oOption=null; for(var i=theObjOptions.length-1;i>-1;i--) { if( theObjOptions[i].selected ) { if(oOption) { oOption=selectObj.insertBefore(theObjOptions[i],oOption); } else oOption=selectObj.appendChild(theObjOptions[i]); } } selectObj.focus();//For a bug of IE7}function selectAllOption(selectObj){ var theObjOptions=selectObj.options; for(var i=0;i<theObjOptions.length;i++){ theObjOptions[i].selected=true; }}/* private function */function swapOptionProperties(option1,option2){ //option1.swapNode(option2); var tempStr=option1.value; option1.value=option2.value; option2.value=tempStr; tempStr=option1.text; option1.text=option2.text; option2.text=tempStr; tempStr=option1.selected; option1.selected=option2.selected; option2.selected=tempStr;} function resetAutoWidth(obj){ var tempWidth=obj.style.getExpression("width"); if(tempWidth!=null) { obj.style.width="auto"; obj.style.setExpression("width",tempWidth); obj.style.width=null; }}</script></head><script>function saveFun(){ if(!checkAllNecessaryInputs(document.mainForm)) return false; if(document.all.selectedFields.length==0){ alert("Please select fields."); return false; } selectAllOption(document.all.selectedFields); submitXpcForm(document.mainForm);}</script><body leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="5">Sometime we need s<font color="#0000FF">wap options between two multiple-select,</font> we can user the javascript functions in "js/CommonJS_SwapOption.js"<br> Please pay do as the following UI standard:<br> 1.There are <font color="#0000FF"> four buttons </font> as follwing for move options right or left .<br> 2.The two multiple-select should have dblclick event to move options right or left .<br> 3.If need sort order, there will have <font color="#0000FF">four image buttons</font> as follwing .<br> <hr><form name="mainForm" method="post" action="http://www.ecvision.com"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="100%" height="20"></td> <td nowrap align="right"> <input class='button' type='button' value='Edit' disabled name='editButton' disabled > <input class='button' type='button' value='Amend' onclick="alert('Amend');" name='amendButton' > <input class='button' type='button' value='Save' onclick="saveFun();" name='saveButton' > </td> </tr></table><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr class="listViewThS1"> <td align="center" nowrap>General</td> <td width="100%"> </td> </tr></table><table width="100%" align="center" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center" class="attributeLabel">Available Fields </td> <td width="1%" align="center" class="attributeLabel"> </td> <td align="center" class="attributeLabel">Selected Fields</td> <td width="1%" align="center" class="attributeLabel"> </td> </tr> <tr> <td align="center" class="attributeContent"> <select name="barRowAvailableFields" multiple=true size="10" class="ecv_autoSizeDropDown" style="width:200px;" onDblClick="moveLeftOrRight(document.all.barRowAvailableFields,document.all.selectedFields)"> <option value="1">Field 01</option> <option value="1">Field 02</option> <option value="1">Field 03</option> <option value="1">Field 04</option> <option value="1">Field 05</option> <option value="1">Field 06</option> <option value="1">Field 07</option> <option value="1">Field 08</option> <option value="1">Field 09</option> <option value="1">Field 010</option> <option value="1">Field 011</option> <option value="1">Field 012</option> <option value="1">Field 013</option> <option value="1">Field 014</option> <option value="1">Field 015</option> <option value="1">Field 016</option> </select> </td> <td align="center" class="attributeContent"> <input type="button" class="button" style="width:35px;" value=" >> " onClick="moveLeftOrRightAll(document.all.barRowAvailableFields,document.all.selectedFields)"> <br> <input type="button" class="button" style="width:35px;" value=">" onClick="moveLeftOrRight(document.all.barRowAvailableFields,document.all.selectedFields)"> <br> <input type="button" class="button" style="width:35px;" value="<" onClick="moveLeftOrRight(document.all.selectedFields,document.all.barRowAvailableFields)"> <br> <input type="button" class="button" style="width:35px;" value=" << " onClick="moveLeftOrRightAll(document.all.selectedFields,document.all.barRowAvailableFields)"> </td> <td align="center" class="attributeContent"> <select name="selectedFields" multiple=true size="10" class="ecv_autoSizeDropDown" style="width:200px;" onDblClick="moveLeftOrRight(this,document.all.barRowAvailableFields)" > </select> </td> <td width="5%" class="attributeContent" align="center" > <img src="../../img/upTop.gif" onClick="moveToTop(document.all.selectedFields)" style="cursor:hand;"> <br><br> <img src="../../img/up.gif" onClick="moveUp(document.all.selectedFields)" style="cursor:hand;"> <br><br> <img src="../../img/down.gif" onClick="moveDown(document.all.selectedFields)" style="cursor:hand;"> <br><br> <img src="../../img/downBottom.gif" onClick=" moveToBottom(document.all.selectedFields)" style="cursor:hand;"> </td> </tr></table></form></body> extjs 修改checkbox的boxlabel 求助:JScript写画笔功能! 求助:实现左边复选框的内容添加到右边的框中 textarea 中如何得到鼠标选择的文字 关于IFRAME的问题? 怎样作出如图http://www.tunnel.net.cn/a.jpg样子? 如何取得radio的值? 刚学JavaScript,问了大家不少问题,谢谢大家的热情回复。我自己也做了个“进度条”,分享给大家。绝对原创! 简单问题,求教? 一个大家都很棘手的问题 【【【【这条语句写在字符串中需要加什么? 怎么一直报未定义??????】】】】】 问一个选项卡的问题!
for(var i=0;i<document.listbox2.options.length;i++){
if (xxxx == document.listbox2.options[i].value){
alert();return false;
}
}
<head>
<link rel="stylesheet" href="../../css/xpc.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ecVision XpressCommerce</title>
<script language="javascript" srccccccc="../../js/CommonJS_SwapOption.js">function moveLeftOrRight(fromObj,toObj)
{
var fromObjOptions=fromObj.options;
for(var i=0;i<fromObjOptions.length;i++){
if(fromObjOptions[i].selected){
toObj.appendChild(fromObjOptions[i]);
i--;
}
}
resetAutoWidth(fromObj);
resetAutoWidth(toObj);
} function moveLeftOrRightAll(fromObj,toObj)
{
var fromObjOptions=fromObj.options;
if(fromObjOptions.length>1000) {
//if(!confirm("Are you sure to move options?")) return false;
}
for(var i=0;i<fromObjOptions.length;i++){
fromObjOptions[0].selected=true;
toObj.appendChild(fromObjOptions[i]);
i--;
}
resetAutoWidth(fromObj);
resetAutoWidth(toObj);
} function moveUp(selectObj)
{
var theObjOptions=selectObj.options;
for(var i=1;i<theObjOptions.length;i++) {
if( theObjOptions[i].selected && !theObjOptions[i-1].selected ) {
swapOptionProperties(theObjOptions[i],theObjOptions[i-1]);
}
}
selectObj.focus();//For a bug of IE7
}
function moveDown(selectObj)
{
var theObjOptions=selectObj.options;
for(var i=theObjOptions.length-2;i>-1;i--) {
if( theObjOptions[i].selected && !theObjOptions[i+1].selected ) {
swapOptionProperties(theObjOptions[i],theObjOptions[i+1]);
}
}
selectObj.focus();//For a bug of IE7
} function moveToTop(selectObj){
var theObjOptions=selectObj.options;
var oOption=null;
for(var i=0;i<theObjOptions.length;i++) {
if( theObjOptions[i].selected && oOption) {
selectObj.insertBefore(theObjOptions[i],oOption);
}
else if(!oOption && !theObjOptions[i].selected) {
oOption=theObjOptions[i];
}
}
selectObj.focus();//For a bug of IE7
}function moveToBottom(selectObj){
var theObjOptions=selectObj.options;
var oOption=null;
for(var i=theObjOptions.length-1;i>-1;i--) {
if( theObjOptions[i].selected ) {
if(oOption) {
oOption=selectObj.insertBefore(theObjOptions[i],oOption);
}
else oOption=selectObj.appendChild(theObjOptions[i]);
}
}
selectObj.focus();//For a bug of IE7
}function selectAllOption(selectObj){
var theObjOptions=selectObj.options;
for(var i=0;i<theObjOptions.length;i++){
theObjOptions[i].selected=true;
}
}/* private function */
function swapOptionProperties(option1,option2){
//option1.swapNode(option2);
var tempStr=option1.value;
option1.value=option2.value;
option2.value=tempStr;
tempStr=option1.text;
option1.text=option2.text;
option2.text=tempStr;
tempStr=option1.selected;
option1.selected=option2.selected;
option2.selected=tempStr;
}
function resetAutoWidth(obj){
var tempWidth=obj.style.getExpression("width");
if(tempWidth!=null) {
obj.style.width="auto";
obj.style.setExpression("width",tempWidth);
obj.style.width=null;
}
}
</script>
</head>
<script>
function saveFun(){
if(!checkAllNecessaryInputs(document.mainForm)) return false;
if(document.all.selectedFields.length==0){
alert("Please select fields.");
return false;
}
selectAllOption(document.all.selectedFields);
submitXpcForm(document.mainForm);
}
</script><body leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="5">
Sometime we need s<font color="#0000FF">wap options between two multiple-select,</font> we can user the javascript functions in "js/CommonJS_SwapOption.js"<br>
Please pay do as the following UI standard:<br>
1.There are <font color="#0000FF"> four buttons </font> as follwing for move options right or left .<br>
2.The two multiple-select should have dblclick event to move options right or left .<br>
3.If need sort order, there will have <font color="#0000FF">four image buttons</font> as follwing .<br>
<hr><form name="mainForm" method="post" action="http://www.ecvision.com"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" height="20"></td>
<td nowrap align="right">
<input class='button' type='button' value='Edit' disabled name='editButton' disabled >
<input class='button' type='button' value='Amend' onclick="alert('Amend');" name='amendButton' >
<input class='button' type='button' value='Save' onclick="saveFun();" name='saveButton' >
</td>
</tr>
</table><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr class="listViewThS1">
<td align="center" nowrap>General</td>
<td width="100%"> </td>
</tr>
</table><table width="100%" align="center" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center" class="attributeLabel">Available Fields </td>
<td width="1%" align="center" class="attributeLabel"> </td>
<td align="center" class="attributeLabel">Selected Fields</td>
<td width="1%" align="center" class="attributeLabel"> </td>
</tr>
<tr>
<td align="center" class="attributeContent">
<select name="barRowAvailableFields" multiple=true size="10" class="ecv_autoSizeDropDown" style="width:200px;"
onDblClick="moveLeftOrRight(document.all.barRowAvailableFields,document.all.selectedFields)">
<option value="1">Field 01</option>
<option value="1">Field 02</option>
<option value="1">Field 03</option>
<option value="1">Field 04</option>
<option value="1">Field 05</option>
<option value="1">Field 06</option>
<option value="1">Field 07</option>
<option value="1">Field 08</option>
<option value="1">Field 09</option>
<option value="1">Field 010</option>
<option value="1">Field 011</option>
<option value="1">Field 012</option>
<option value="1">Field 013</option>
<option value="1">Field 014</option>
<option value="1">Field 015</option>
<option value="1">Field 016</option>
</select>
</td>
<td align="center" class="attributeContent">
<input type="button" class="button" style="width:35px;" value=" >> " onClick="moveLeftOrRightAll(document.all.barRowAvailableFields,document.all.selectedFields)">
<br>
<input type="button" class="button" style="width:35px;" value=">" onClick="moveLeftOrRight(document.all.barRowAvailableFields,document.all.selectedFields)">
<br>
<input type="button" class="button" style="width:35px;" value="<" onClick="moveLeftOrRight(document.all.selectedFields,document.all.barRowAvailableFields)">
<br>
<input type="button" class="button" style="width:35px;" value=" << " onClick="moveLeftOrRightAll(document.all.selectedFields,document.all.barRowAvailableFields)">
</td>
<td align="center" class="attributeContent">
<select name="selectedFields" multiple=true size="10" class="ecv_autoSizeDropDown" style="width:200px;" onDblClick="moveLeftOrRight(this,document.all.barRowAvailableFields)" >
</select>
</td>
<td width="5%" class="attributeContent" align="center" >
<img src="../../img/upTop.gif" onClick="moveToTop(document.all.selectedFields)" style="cursor:hand;">
<br><br>
<img src="../../img/up.gif" onClick="moveUp(document.all.selectedFields)" style="cursor:hand;">
<br><br>
<img src="../../img/down.gif" onClick="moveDown(document.all.selectedFields)" style="cursor:hand;">
<br><br>
<img src="../../img/downBottom.gif" onClick=" moveToBottom(document.all.selectedFields)" style="cursor:hand;"> </td>
</tr>
</table></form>
</body>