Home  >  Article  >  Backend Development  >  移动到右边的,为什么要选中后提交才能获取到相应的值。

移动到右边的,为什么要选中后提交才能获取到相应的值。

WBOY
WBOYOriginal
2016-06-23 14:24:08806browse

本帖最后由 qq914260102 于 2013-10-14 16:02:07 编辑

如果选到右边,是无法获取到值的,必须要点击一次,选中了才能获取到,怎么让右边的默认能获取值








> " onclick="move(this.form.list1,this.form.list2)" name="B1">




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;   }}

回复讨论(解决方案)

懒得看代码理解,纯想象
form提交,select只提交选择的option
所以如果要提交list2,要把全部都加设selected属性,或者把option的每个value都赋值一个新控件(例如hidden)来提交

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:答疑啊Next article:php 加密狗的调用方法