JavaScript operation Select element Instance Analysis _javascript technique

Source: Internet
Author: User

This example describes the use of the JavaScript action select element. Share to everyone for your reference. The specific analysis is as follows:

Here is familiar with the operation of the Select element JS, the HTML page to create a form, which contains a SELECT element and submit button.

When you select an item in select, change its text, and then restore the text when all the items in the select are changed.

When you press submit, close the window itself, the code is as follows:

<! DOCTYPE html>  

In Firefox at first seemingly unable to close the window itself, later found in About:config set Dom.allow_scripts_to_close_windows to True.

If the options in each select are not regular, you can write a on_change_ex to process the code as follows:

function do_change_ex (Me) {
  var text = me[me.selectedindex].innerhtml;
  if (!text.match (/\[/)) {
   Me[me.selectedindex].text_bak = me[me.selectedindex].innerhtml;
   me[me.selectedindex].innerhtml + = "[Duang]";
   Me[me.selectedindex].is_changed = true;
  }
  var is_all_seleted = true;
  for (Var i=0;i<me.length;++i) {
   if (!me[i].is_changed) {
    is_all_seleted = false;
    break;
   }
  }
  if (is_all_seleted) {
   alert ("All Duang!!! \nand reset IT!!! ");
   for (Var i=0;i<me.length;++i) {
    me[i].innerhtml = Me[i].text_bak;
    me[i].is_changed = false;}}}

I hope this article will help you with your JavaScript programming.

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.