JavaScript: The Definitive Guide, Sixth Editio javaScript权威指南(第6版) pdf 文字版-文字版, javascript电子书, 和javascript 有关的电子书:

15.9.6 Text Fields

When the user clicks on a toggle button, the radio or checkbox element triggers its onclick handlers. If the toggle button changes state as the result of the click, it also triggers the onchange event handlers. (Note, however, that radio buttons that change state when the user clicks on a different radio button do not fire an onchange handler.)


15.9.6 Text Fields

Text input fields are probably the most commonly used element in HTML forms and JavaScript programs. They allow the user to enter a short, single-line string of text. The value property represents the text the user has entered. You can set this property to specify explicitly the text that should be displayed in the field.

In HTML5, the placeholderattribute specifies a prompt to be displayed within the field before the user enters anything:

Arrival Date:

A text field’s onchange event handler is triggered when the user enters new text or edits existing text and then indicates that he is finished editing by moving input focus out of the text field.

The Textarea element is like a text input field element, except that it allows the user to input (and your JavaScript programs to display) multiline text. Textarea elements are created with atag using a syntax significantly different from thetag that creates a text field. (See TextArea in Part IV .) Nevertheless, the two types of elements behave quite similarly. You can use the value property and onchange event handler of a Textarea element just as you can for a Text element.

Anelement is a modified input field that displays asterisks as the user types into it. As the name indicates, this is useful to allow a user to enter passwords without worrying about others reading over his shoulder. Note that the Password element protects the user’s input from prying eyes, but when the form is submitted, that input is not encrypted in any way (unless it is submitted over a secure HTTPS connection), and it may be visible as it is transmitted over the network.

Finally, anelement allows the user to enter the name of a file to be uploaded to the web server. It is a text field combined with a button that opens a file-chooser dialog box. This file selection element has an onchange event handler, like a regular input field. Unlike an input field, however, the valueproperty of a file selection element is read-only. This prevents malicious JavaScript programs from tricking the user into uploading a file that should not be shared.

The various text input elements define onkeypress, onkeydown, and onkeyup event handlers. You can return falsefrom the onkeypress or onkeydownevent handlers to prevent the user’s keystroke from being recorded. This can be useful, for example, if you want to force the user to enter only digits into a particular text input field. See Exam ple 17-6 for a demonstration of this technique.

欢迎转载,转载请注明来自一手册:http://yishouce.com/book/1/30636.html
友情链接It题库(ittiku.com)| 版权归yishouce.com所有| 友链等可联系 admin#yishouce.com|粤ICP备16001685号-1