JavaScript basics
JavaScript onchange event
The JavaScript onChange event can be used on HTML Form elements such as input text , textarea , select option, etc. When the content of the element changes, the onChange event is triggered to execute the JavaScript code you have prepared. The scope of application is quite large, please see The following example. JavaScript onChange Event example
<script type="text/javascript">
function ShowStr(x){
var Str=document.getElementById(x).value;
alert(Str);
}
</script>
請隨意輸入幾個文字:<input type="text" id="Str" onchange="ShowStr(this.id)">
Present resultsfunction ShowStr(x){
var Str=document.getElementById(x).value;
alert(Str);
}
</script>
請隨意輸入幾個文字:<input type="text" id="Str" onchange="ShowStr(this.id)">
Please enter a few words at will:
In the example, we first wrote a function ShowStr, this ShowStr will automatically capture the content of the string filled in by netizens, the input text input field below the example is for netizens to fill in words, it will not be used when filling in words Trigger onChange Event. After filling in the text, move the mouse away from the text field to trigger onChange Event, execute the code in ShowStr, and the browser will open a dialog window to tell you what you just filled in.
The JavaScript onChange event is also often used to make the select option jump page menu. Netizens select the webpage they want to go to in the drop-down menu. When the option changes, the onChange event is automatically triggered to take the netizen to the destination they choose. Refer to this article: JavaScript select onChange jump page menu .
Post a Comment
0 Comments