[英]how to parse attribute onclick, which contains return function. javascript
I have a link which return form with different ID's, and i need to get ID number from onclick attribute 我有一个返回带有不同ID的表单的链接,我需要从onclick属性获取ID号
<a onclick="return package_order(14400287396);" href="javascript:;">advanced</a>
<a>doit</a>
this jquery code: 这个jQuery代码:
var pack = $('a:contains("advanced")').attr("onclick");
$('a:contains("doit")').click(function(){
alert(pack)
and i get: 我得到:
function onclick(event) {
return package_order(14400287396);
}
but i need only id number inside() should i use regular expression to do it? 但我只需要ID号inside()就可以使用正则表达式来做到这一点? or what?
要不然是啥?
从onclick
属性中提取的“ id”是这样的:
$('a:contains("advanced")').attr("onclick").match(/\d+(?=\))/)[0]
you could do 你可以做
var idStr = pack.split('(')[1];
var id = idStr.substring(0, idStr.length-2);
which will split that string into an array based on the first left paren, and then take the second array value, then subtract the last 2 chars 它将根据第一个左括号将字符串拆分成一个数组,然后获取第二个数组值,然后减去最后两个字符
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.