添加/删除<选项>来自< select>的商品使用javascript [英] add/remove <option> items from a <select> using javascript

查看:63
本文介绍了添加/删除<选项>来自< select>的商品使用javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在表格中我有5个元素(例如图片),我希望用户能够设置外观的顺序。为此,我为每张图片选择了一个选项框(名称select1 to select5),并带有请选择一些东西。如预选,其余选项是从1到5的值。我想当用户选择一个数字a.k.a ans< option>那个数字/<选项>要从其他选择框中删除,当用户选择另一个数字时,取消选择的一个(先前选择的)出现在其他选择框中如何使用Javascript完成?

In a form I have 5 elements (e.g. pictures) and I wish for the user to be able to set the order of appearance. For this I have for each picture a select box (names select1 to select5) with "please select something" as preselected and the rest options are values from 1 to 5. I want when a user selects a number a.k.a ans <option> that number/<option> to be removed from the rest of the select boxes and when the user selects another number the deselected one (previously selected) to appear on the other select boxes How can this be done with Javascript?

推荐答案

而不是那个,只有一个选择,侧面有两个按钮Up。和向下向上或向下移动选定的选项以确定外观的顺序?

无论如何,要添加选项,请使用带有Option对象的options数组:
Instead of that, how about just one select with two buttons on the side "Up" and "Down" to move the selected option up or down to determine the order of appearance?

Anyway, to add an option, use the options array with the Option object:
展开 | 选择 | Wrap | 行号



而不是那个,只有一个选项,旁边有两个按钮Up ;和向下向上或向下移动选定的选项以确定外观的顺序?
Instead of that, how about just one select with two buttons on the side "Up" and "Down" to move the selected option up or down to determine the order of appearance?



任何想法如何做到这一点(如何使按钮以这种方式工作)?

any idea how to do this (how to make the buttons work this way)?


你可以创建一个temp。选项和交换,例如伪代码
You could create a temp. option and swap, e.g. pseudocode
展开 | 选择 | Wrap | 行号


这篇关于添加/删除&lt;选项&gt;来自&lt; select&gt;的商品使用javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆