简体   繁体   中英

How to get the value of the method parameter using javascript?

<a onclick="ToggleGridViewRows(this,'/SharedDocuments/1.0 Qualify');">
   <img src="../../../../../../../_layouts/images/collapseminus.gif" />
</a>

The above link tag has an onclick event which has the js method "ToggleGridViewRows".

I need to fetch the second parameter "'/SharedDocuments/1.0 Qualify'" value using js.

How can I do this.

var k = document.getElementById('foo').getAttribute('onclick');

k = k.split("\'");

alert(k[1]);

Fiddle here .

This example assumes your <a> element has an ID of 'foo'. If you want to get all 'onclick' content of every <a> element, you can use document.getElementsByTagName('a') .

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