Javascript将ID添加到HTML href
16lz
2021-01-22
I have a livesearch script that i need to populate my html menu with information.
我有一个livesearch脚本,我需要用信息填充我的html菜单。
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>
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.
我有一个Javascript从数据库表(livesearch)中提取值ID,现在我只需要它即时进入href。
Any suggestions?
有什么建议么?
2 个解决方案
#1
2
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";
}
}
更多相关文章
- 组合两个下拉菜单以确定提交按钮链接
- css+html实现自适应宽度的菜单学习
- 纯JS幻灯片菜单,能够“点击菜单外点击”
- 用无序列表键入文本脚本
- Python脚本利用openoffice将office文档转为html或者pdf。
- 您试图显示配置为只允许执行和脚本权限的目录中的 HTML 页
- 我使用生成html文件的python制作了一个脚本。如何使用Web爬网程
- html5在pc能实现下拉菜单,在手机实现不了
- 我可以在所有浏览器中使用我的屏幕外菜单吗?