Note:
i > Each form element should try to use the tag to improve user experience;
ii > Each Each form element should be assigned a name attribute and an id attribute.
The name attribute: used to submit data to the server;
The id attribute: used to perform corresponding operations on the client; such as: label binding, CSS selector The use of etc.
(The name attribute and id attribute should use the same or related values whenever possible.)
On the client side, Javascript handles forms and form elements For operations, it is preferred to use its name attribute.
Because, for some specific form elements (such as radio buttons, etc.), it is easier to obtain the element value using its name attribute, and it is also more convenient to transmit data to the server!
Javascript operates form form elements, less commonly used attributes:
defaultChecked sets or gets the check box or radio button status. defaultValue sets or gets the initial content of the object. disabled Sets or gets the status of the control.
Submit form
Example of submitting form:
This is different from submitting elements with ;
ii > You can use the disabled attribute in the submit or click event of the button to disable the user from repeatedly clicking submit Button behavior,
Reduce the response burden on the server;
Set text box
i > Control Number of characters in the text box
##
function LessThan(_textArea){
//Returns the boolean value of whether the number of characters in the text box is required by the symbol
return _textArea.value .length < _textArea.getAttribute("maxlength"); }
Text box:
##
##< label for="comments">Multi-line text box:
##
Note: The maxlength in the multi-line text box
ii > When the mouse passes over, the text box is automatically selected
Achieves the separation of behavior and structure.
Set the radio button
Get the selected radio button & set the radio button to be selected
//Call code
You need to ensure that the name attribute value of the same group of radio buttons is the same.
Set the check box
Set the check box's "select all", "unselect all" and "inverse selection" Function
##
##
## aa
## bb
Set the drop-down list box
The multiple attribute of the drop-down list box is used to set or get the drop-down list Whether the box can select multiple options.
The drop-down list box can only select one item by default. If you want to set it to select multiple items, then .
type attribute: JavaScript language obtains the type of the drop-down list box select control based on the value of the type attribute.
The value of the type attribute is: select-multiple or select-one (Note: the type of the drop-down list box is controlled by the multiple attribute)
i > View the options of the drop-down list box (single option & multiple options)
##function AddOption(Box){ // Append options to the end
var oForm = document.forms["myForm1"];
var oBox = oForm.elements[Box];
## var oOption = new Option("ping pong","Pingpang");
oBox.options[oBox.options.length] = oOption;
}
##
##
Insert new options into the specified position
iv > Delete an option
##
##
##
......
##
Delete options directly through oBox.options[_num] = null.