JavaScript onclick event

 The JavaScript onclick event (Event) is used to trigger a certain JavaScript action, which can be used in a form or somewhere in a web page. A common application in a form is, for example, when a netizen selects an item in a menu, the JavaScript onclick knows the item’s status value, and then display the second-level items for users to choose. There is a very interesting idea. For example, for Western-style meals, make a ready-to-order form, let consumers order the appetizer, automatically display the type of bread for selection, automatically display the salad type, and then automatically display the type of meal... Until the entire package is completed, when the consumer clicks the action, it can be made with JavaScript onclick. This is just a digression, let’s look at a simple example.


JavaScript onclick event (Event) example
<script language="javascript">
function ShowMeDate() {
 var Today=new Date();
 alert("Today's date is" + Today.getFullYear()+ "year" + (Today.getMonth()+1) + " Month" + Today.getDate() + "Day");
}
</script>
<button onclick="ShowMeDate()">Tell me today’s date</button>
Present results


In this example, we first wrote a simple function to display today’s date, but just writing such a function will not automatically display it, it must be triggered by an event to display it, so the last line writes a button ( HTML button ), when the button "Tell me today's date" is pressed, onclick will automatically trigger ShowMeDate() and execute the display of today's date . Please refer to this article for the date obtained by JavaScript : JavaScript Get Today's Date .

Post a Comment

0 Comments