简体   繁体   中英

Extracting value from onclick function call

In jQuery, how do I extract the number 4 from the doThisThing() function call from an onclick event:

<div id="div1" onclick="doThisThing(4)"></div>

and how do I set it?

Thanks.

Is this what you mean? And why do you need to set it, too? Maybe you could explain what you're trying to do so we can better help you.

$(document).ready(function() {
    $('#div1').attr('onclick', 'doThisThing(4)');
});

Once you are in the function itself you will have access to it:

function doThisTHing(inputValue)
{
   alert(inputValue);
}

How you set what gets passed depends on what you are trying to pass.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM