Home Web Front-end HTML Tutorial Detailed explanation of the selected attribute when converting into in html

Detailed explanation of the selected attribute when converting into in html

Jul 03, 2017 am 10:08 AM
html option

1. Concept introduction

The use of html tags in stust1, including html:select, html:option, details are as follows

<html:select property="test
String
" size="1">
    <html:option value="value1">Show Value1</html:option>
    <html:option value="value2">Show Value2</html:option>
    <html:option value="value3">Show Value3</html:option>
    <:html:submit property="submit" value="提交"/> </html:select>
Copy after login


Among them, property represents the corresponding property name in the selection list and ActionForm. When the user clicks submit, the value of the option selected by the user will be seen on the test page. The following is the running effect of the code:

Show Value1 Show Value2 Show Value3

has a size attribute, which means The number of options displayed at the same time. For example, if size is 1 in the above example, only one option will be displayed at the same time. There is also a multiple attribute. When it is true, the selection list allows multiple selections. Users can drag the mouse or hold down the Ctrl key to perform multiple selections.

The following is an example of multiple="true" and size="8"

value1 value2 value3 value4 value5 value6 value7 value8 value9 value10

When the multiple attribute is true, in The corresponding property in ActionForm should be an arraytype so that multiple values ​​selected by the user can be assigned to it at the same time.

tag is the option of the tag, each will be represented in the select box an option. The following code is shown:

<html:select property="testString" size="1">
    <html:option value="value1">Show Value1</html:option>
    <html:option value="value2">Show Value2</html:option>
    <html:option value="value3">Show Value3</html:option>
</html:select>
Copy after login


An option has two important parts. The first is the content it displays to the user, which can be specified in the following way:

    <html:option value="value1">Show Value1</html:option>
Copy after login

As can be seen, the part between two is used to represent the content the user sees. . Of course, you can also use the key and bundle attributes of to specify the content in the resource file to represent the content seen by the user. For the usage of bundle and key attributes, please refer to the relevant chapters of "Configuration File".

Another important content is the value it passes to ActionForm. This is specified by the tag's value attribute. As in the above example, the values ​​of value are value1, value2 and value3 respectively. When the user selects a certain tag, the JSP page will pass the value corresponding to the tag to the corresponding attribute in the ActionForm.

The following is the running effect:

Show Value1 Show Value2 Show Value3
Copy after login

2. Secrets that cannot be told

<html:option></html:option>转化成<option></option>时加了selected属性,RTFSC,看源码

if(selectTag().isMatched(value))
    results.append(" selected=\"selected\"");



public boolean isMatched(String value)
            {
/* <-MISALIGNED-> */ /* 126*/        if(match == null || value == null)
/* <-MISALIGNED-> */ /* 127*/            return false;
/* <-MISALIGNED-> */ /* 130*/        for(int i = 0; i < match.length; i++)
/* <-MISALIGNED-> */ /* 131*/            if(value.equals(match[i]))
/* <-MISALIGNED-> */ /* 132*/                return true;
/* <-MISALIGNED-> */ /* 135*/        return false;
            }



if(value != null)
                {/* 234*/            match = new String[1];
/* 235*/            match[0] = value;
                } else
                {
/* 238*/            Object bean = TagUtils.getInstance().lookup(super.pageContext, name, null);
/* 239*/            if(bean == null)
                    {/* 240*/                JspException e = new JspException(messages.getMessage("getter.bean", name));


/* 243*/                TagUtils.getInstance().saveException(super.pageContext, e);
/* 244*/                throw e;
                    }


/* 248*/            try
                    {
/* <-MISALIGNED-> */ /* 248*/                match = BeanUtils.getArrayProperty(bean, property);    //获取form中的select的value值
/* <-MISALIGNED-> */ /* 249*/                if(match == null)
/* <-MISALIGNED-> */ /* 250*/                    match = new String[0];
                    }
/* 254*/            catch(IllegalAccessException e)
                    {
/* <-MISALIGNED-> */ /* 254*/                TagUtils.getInstance().saveException(super.pageContext, e);
/* <-MISALIGNED-> */ /* 255*/                throw new JspException(messages.getMessage("getter.access", property, name));
                    }
Copy after login

3. Unsolved problems, how to set the default selection using html:option, there is no selected attributeDetailed explanation of the selected attribute when converting <html:option></html:option> into <option></option> in html



The above is the detailed content of Detailed explanation of the selected attribute when converting into in html. 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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles