JavaScript multiple onclick function take corresponding value

Source: Internet
Author: User

Method 1: Get the value directly

<button onclick= "AA (1)" > Executive </button>

<button onclick= "AA (2)" > Executive </button>

<button onclick= "AA (3)" > Executive </button>

<button onclick= "AA (4)" > Executive </button>

<script>

function AA (v) {alert (v); }

</script>

Method 2: Use the corresponding value (mainly the use of this)

<button value= "1" onclick= "AA (This)" > Executive </button>

<button value= "2" onclick= "AA (This)" > Executive </button>

<button value= "3" onclick= "AA (This)" > Executive </button>

<button value= "4" onclick= "AA (This)" > Executive </button>

<script>

function AA (t) {alert (t.value)}

</script>

Method 3: Do not directly transmit the parameter event.target get

<button value= "1" onclick= "" > Execution </button>

<button value= "2" onclick= "" > Execution </button>

<button value= "3" onclick= "" > Execution </button>

<button value= "4" onclick= "" > Execution </button>

<script>

function AA () {alert (Event.target.value)}

</script>

JavaScript multiple onclick function take corresponding value

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.