One-choice and multiple-choice instances are implemented based on javascript to move the instances to the right and left, and one-choice javascript operation is performed.

Source: Internet
Author: User

One-choice and multiple-choice instances are implemented based on javascript to move the instances to the right and left, and one-choice javascript operation is performed.

This example describes how to implement one-or-multiple-choice to the right and move to the left Based on javascript. Share it with you for your reference. The specific implementation method is as follows:

Method 1:

<Body> 

Method 2:

<Script type = "text/javascript"> sortitems = 1; 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 ;}} </script> 

I hope this article will help you design javascript programs.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.