Javascript将ID添加到HTML href [英] Javascript add ID to HTML href
本文介绍了Javascript将ID添加到HTML href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个livesearch脚本,需要用信息填充html菜单.
I have a livesearch script that i need to populate my html menu with information.
我有一个菜单,看起来像这样:
i have a menu how looks something like this:
<a href="?page=page&id=">Menu item</a>
我正在寻找的是一段将对链接执行此操作的代码:
what i'm looking for is a piece of code that would do this to the link:
<a href="?page=page&id=1">Menu item</a>
我有一个Javascript可从数据库表(实时搜索)中提取值ID,现在我只需要它即可即时进入href.
i have a Javascript that pulls out value ID from a database table (livesearch), now i only need it to get into the href on the fly.
有什么建议吗?
推荐答案
function addPageIds(){
var links = document.getElementsByTagName("a");
for (var i = 0; i < links.length; i++){
if (/id=$/.test(links[i].href)) links[i].href += "1";
}
}
这篇关于Javascript将ID添加到HTML href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文