Js click the text box to pop up the selectable checkbox check box,

Source: Internet
Author: User

Js click the text box to pop up the selectable checkbox check box,

This article shares a code example. When you click the text box, the checkbox check box in the drop-down box is displayed. You can select the check box to write the value to the text box, it may not be so straightforward and simple in practical application, but it can be demonstrated as an example to facilitate the learner's understanding and expansion.
The Code is as follows:

<Html> 

The above Code meets our requirements. Next we will introduce its implementation process.
Code comment:
1. $ (function (){}),After the document structure is fully loaded, execute the code in the function.
2. var position = $ ("# xx"). offset (),Get the offset of the text box relative to the document. The offset () function returns an object that contains the left and top attributes, indicating the horizontal and vertical offset relative to the document, respectively.
3. $ ("# div1"). offset ({top: position. top + 22, left: position. left }),Set the Relative document offset of the pop-up drop-down menu container. The first plus 22 is used to display it under the text box.
4. $ ("# xx"). click (function () {$ ("# NG"). toggleClass ("open ");}),Register the click event handler for the text box. click it to switch to the style class open Delete and add, that is, set the display and hide of the drop-down menu.
5. $ ("# div1 input [name = ng]"). click (function (){}),Register the click event handler function for the text box whose value is ng.
6. var arr = new Array (),Create an array to store the value of the checkbox check box.
7. $ ("input [name = ng]: checked "). each (function (key, value) {arr [key] = $ (value ). val ();}),Store the value of the selected check box to an array.
8. $ ("# xx"). val (arr. join (","));,Concatenates array elements into strings and writes them into the text box.

I hope this article will help you learn about javascript programming.

Articles you may be interested in:
  • Javascript checks whether a single sequence or check box selects a method collection
  • Jsp check box usage
  • Code for JSP single-choice button verification, drop-down box verification, and check box Verification
  • Js checkbox usage highlights
  • Js to obtain the value and operation of a single sequence or check box
  • How to dynamically Add a Checkbox instance in Js
  • Example of the option selected by js to obtain the checkbox check box
  • A drop-down box with check boxes implemented by js + csss
  • JS implementation click the check box to change the button or text box to gray unavailable Method
  • Js achieves the pop-up layer effect of the Discuz text box

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.