如何抓取 URL 的一部分并将其粘贴到页面的某个位置

How to grab parts of URL and paste it somewhere on the page

我的 mediawiki 网站需要一个 javascript(最好),它将抓住 url 的结尾,例如来自 http://aionpowerbook.com/powerbook/125004192 我希望它获取 ID 125004192,然后像这样将其添加到同一页面的某处

<a id="various3" href="http://aionpowerbook.com/view.php?item=placed_id">

请求将是静态的,ID 将添加到“?item=”之后,这将导致:

<a id="various3" href="http://aionpowerbook.com/view.php?item=125004192">

这可能吗?

更新: 我不得不稍微修改一下你的建议,但最后它奏效了

<a id="various3" />
<script type="text/javascript">
  var itemid = document.URL.split("/").slice(-1)[0];
  var a = document.getElementById('various3');
  if (a) {
    a.href = "http://aionpowerbook.com/view.php?item=" + itemid;;
  }
</script>

谢谢。

var link = document.getElementBYId("various3");
var id = document.URL.split("/").slice(-1)[0];
link.href = "http://aionpowerbook.com/view.php?item=" + id;