Home Web Front-end JS Tutorial Introduction to JavaScript framework (xmlplus) components (3) TextBox (TextBox)

Introduction to JavaScript framework (xmlplus) components (3) TextBox (TextBox)

May 04, 2017 am 10:21 AM
text box

xmlplus is a JavaScriptframework used for rapid development of front-end and back-end projects. This article mainly introduces the text box of the xmlplus component design series, which has certain reference value. Interested friends can refer to it

The text box is the most commonly used input component on the page, and its default use The method is as follows:


Of course, the `type='text' here can be omitted. . In most cases, there is no problem using the default text box as the input component, but in specific projects, there will inevitably be a need for functional expansion. Here we only take how to increase the formatted input output capability of text box data as an example to illustrate how to extend the native text box component. In addition to the content of this chapter, you can also refer to the Parameter Mapping chapter in the official documentation.

Functional Analysis of Target Component

For the native text box, the value we obtain is of text type, as shown in the following example :

1

2

3

4

5

6

Example: {

  xml: "<input id=&#39;input&#39; value=&#39;text&#39;/>",

  fun: function (sys, items, opts) {

    console.log(typeof this.prop("value")); // string

  }

}

Copy after login

If you need other types of values, you need to format the obtained data. For example, if you need an integer number, you need to use the parseInt function; if you need a floating point number, you need to use the parseFloat function. If we can encapsulate the operation of formatting data, it will be quite convenient to use. In order to clarify our expectations, we might as well give a example of the use of the target component.

1

2

3

4

5

6

7

8

9

10

11

12

Index: {

  xml: "<p id=&#39;index&#39;>\

       <TextBox id=&#39;foo&#39;/>\

       <TextBox id=&#39;bar&#39; format=&#39;int&#39;/>\

     </p>",

  fun: function (sys, items, opts) {

    items.foo.value = "hello, world";

    items.bar.value = 27.1828;

    console.log("foo", items.foo.value);

    console.log("bar", items.bar.value);

  }

}

Copy after login

This example instantiates two components Input. The component Input is allowed to receive a format parameter as its static interface input, and provide a attribute value as its dynamic input and output interface. The format parameter has three possible values: string (default), int, and float. These three values ​​respectively correspond to three data types: string type, integer type and floating point type. The attribute value formats input and output according to the value of format. The output of the example should look like this:

hello, world
227

Implementation of the target component

In order to complete the above target component, we first give a component framework of a text box.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

TextBox: {

  xml: "<input id=&#39;input&#39; type=&#39;text&#39;/>",

  opt: { format: "string" },

  fun: function (sys, items, opts) {

    var parse = {"int": parseInt, "float": parseFloat, "string": String}[opts.format];

    function getValue() {

      // 这里需要获取 input 的值并根据 opts.format 值选择适当的格式化函数,

    }

    function setValue(value) {

      // 这里需要根据 opts.format 值选择适当的格式化函数,对 value 进行格式化后同去赋值

    }

    return Object.defineProperty({}, "value", { get: getValue, set: setValue });

  }

}

Copy after login

The key point above is the selection of the formatting function. For simplicity, we use the tablequery method. This function is ready during the component initialization phase. The above parse function is the required formatting function. However, it should be noted that the formatting function type of this component is fixed when the component is initialized. If you need variable formatting functions, you need to make some modifications to the component. Okay, the complete text box component can be given below.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

TextBox: {

  xml: "<input id=&#39;input&#39; type=&#39;text&#39;/>",

  opt: { format: &#39;string&#39; },

  map: { attrs: { input: "disabled value placeholder readonly" } },

  fun: function (sys, items, opts) {

    var parse = {"int": parseInt, "float": parseFloat, "string": String}[opts.format];

    function getValue() {

      return parse(sys.input.prop("value"));

    }

    function setValue(value) {

      sys.input.prop("value", parse(value));

    }

    return Object.defineProperty({}, "value", { get: getValue, set: setValue });

  }

}

Copy after login

Also please note that the above components have added some attribute mapping content, which can be added or deleted as needed in specific projects.

This series of articles is based on the xmlplus framework. If you don’t know much about xmlplus, you can visit www.xmlplus.cn. Detailed getting started documentation is available here.

The above is the detailed content of Introduction to JavaScript framework (xmlplus) components (3) TextBox (TextBox). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to set a picture as the background in OneNote How to set a picture as the background in OneNote May 14, 2023 am 11:16 AM

Onenote is one of the best note-taking tools offered by Microsoft. Combined with Outlook and MSTeams, Onenote can be a powerful combination for increasing productivity at work and in personal creative productivity. We have to take notes in a different format, which may be more than just writing things down. Sometimes we need to copy images from different sources and do some editing in our daily work. Images pasted on Onenote can go a long way if you know how to apply the changes. Have you ever encountered a problem when using Onenote that images pasted on Onenote cannot allow you to work easily? This article will look at using images effectively on Onenote. we can

How to hide text until clicked in Powerpoint How to hide text until clicked in Powerpoint Apr 14, 2023 pm 04:40 PM

How to hide text before any click in PowerPoint If you want text to appear when you click anywhere on a PowerPoint slide, setting it up is quick and easy. To hide text before clicking any button in PowerPoint: Open your PowerPoint document and click the Insert menu. Click on New Slide. Choose Blank or one of the other presets. Still in the Insert menu, click Text Box. Drag a text box onto the slide. Click the text box and enter your

How to make a calendar in Word How to make a calendar in Word Apr 25, 2023 pm 02:34 PM

How to Make a Calendar in Word Using Tables If you want to create a calendar that fits your specifications exactly, you can do everything from scratch using tables in Word. This allows you to design the exact layout you want for your calendar. Create a calendar using tables in Word: Open a new Word document. Press Enter a few times to move the cursor down the page. Click the Insert menu. In the ribbon, click the table icon. Click and hold the upper left square and drag out a 7×6 table. Write the day of the week on the first line. Use another calendar as a reference to fill in the days of the month. Highlight any date outside the current month. In the main menu, click the text color icon and select Gray. For the current month, start with

What are the types of html text boxes? What are the types of html text boxes? Oct 12, 2023 pm 05:38 PM

HTML text box types include single line text box, password text box, number text box, date text box, time text box, file upload text box, multi-line text box, etc. Detailed introduction: 1. The single-line text box is the most common type of text box, used to accept single-line text input. The user can enter any text in the text box, such as user name, password, email address, etc.; 2. The password text box is used To accept password input, when the user enters the password, the content in the text box will be hidden to protect the user's privacy; 3. Numeric text box, etc.

How to add line breaks in HTML textbox? How to add line breaks in HTML textbox? Sep 04, 2023 am 11:05 AM

To add a newline character to an HTML text area, we can use the HTML newline tag to insert a newline character anywhere. Alternatively, we can also use the CSS property "white-space:pre-wrap" to automatically add line breaks to the text. This is particularly useful when displaying preformatted text in a text area. So let’s discuss ways to add line breaks. Method creates a text area in HTML and assigns it an id. Create a button that, when clicked, will split the text of the text area using line breaks. Now create a function that separates text into newlines. The code of this function is -functionreplacePeriodsWithLineBreaks()

How to write HTML scroll bar text box code How to write HTML scroll bar text box code Feb 19, 2024 pm 07:38 PM

Title: How to write HTML text box code with scroll bar The text box in HTML is one of the commonly used user input controls. In some cases, when the text content is too long, the text box will be displayed incompletely. At this time, we can add a scroll bar to the text box to support scrolling. This article will introduce in detail how to write HTML text box code with scroll bar effect, and give specific code examples. 1. Use the textarea element to create a text box. In HTML, we use the textarea element to create a text box.

How to set the text box border to be transparent How to set the text box border to be transparent Jul 28, 2023 am 10:05 AM

How to set the text box border to be transparent: 1. Open the document, select the inserted text box, right-click and select "Format Object"; 2. In the pop-up box on the right, select "Shape Options" - "Fill and Line" - "Transparency" ”; 3. Adjust the transparency as needed.

How to set the color of the text box border How to set the color of the text box border Jul 28, 2023 am 10:08 AM

How to set the border color of a text box: 1. Select the text or paragraph to which you want to add a border; 2. In the "Paragraph" or "Font" group of the "Home" tab, click the "Border" button; 3. From the drop-down menu Select a border style; 4. Click the "Border Color" button and select the color you want in the pop-up menu; 5. Click the "OK" button to apply the border style and color.

See all articles