我读过的所有内容都说使用元素.onclick 属性,但这似乎不适用于我的情况。我正在尝试解析数字:629216818 并将其设置为变量:fbid。这是一个 Greasemonkey 脚本,因此无法直接编辑 HTML。我不是专业人士,所以我可能只是在做一些愚蠢的事情,但这是我的 HTML 和 Javascript:
<div id="petRightContainer">
<a title = "Pet trainer bonus: Your companion will level 5% faster." href="setup.php?type=companion>Random=8167343321487308">
<div class="petRight" style="background-image:url(/fb/res/gui4/companion/cu_sith.jpg)"></div>
</a>
<div class="petRightLevel">
<a href="#" onClick="publishToWall('http://www.ghost-trappers.com/fb', 'Look at the cool augmentations my companion has received on Ghost Trappers.', 'Look at my new companion on Ghost Trappers! I\'ve named it Jankie. ', null, 'index.php?si=629216818&fromWall=1', 'white/companion_32.jpg', 'companion/wallpost_augmentation_12.jpg', 'companion/wallpost_augmentation_21.jpg', 'companion/wallpost_augmentation_11.jpg', null)">Dog</a>
</div>
等等
<script type="text/javascript">
fbid = 0;
fbidRegex = /\d{3,}(?=&fromWall=1)/;
if ( document.getElementsByClassName("petRightLevel")[0]){
element = document.getElementsByClassName("petRightLevel")[0].firstChild;
codeStore = element.onclick;
fbid = fbidRegex.exec(codeStore);
document.write("it is working ");
}
document.write(fbid);
</script>