javascript 属性值可以通过手动 url 参数确定吗?
我正在尝试显示来自外部 .jsp 文件的数据,该文件的设置如下:
<tag>
<innertag1 id="1">
<innertag1 id="2">
</tag>
<tag>
<innertag2 id="3">
<innertag2 id="4">
</tag>
要仅显示来自一个特定“innertag”标签的信息,我当前正在使用:
NodeList labs = XMLInfo.getElementsByTagName("innertag1");
我希望能够隔离任何轻松地使用特定标签。理论上,我可以创建许多单独的页面,然后简单地将值更改为“innertag2”、“innertag3”等,但这显然有点不切实际。
有没有办法通过 URL 参数确定值?例如,如果我只想显示“innertag2”中的数据,有没有办法让 url http://www.server.com/data.jsp?id=innertag2 调整标记名适当地?
谢谢,任何帮助将不胜感激。
I am trying to display data from an external .jsp file, which is set up something like this:
<tag>
<innertag1 id="1">
<innertag1 id="2">
</tag>
<tag>
<innertag2 id="3">
<innertag2 id="4">
</tag>
To display only information from only one particular "innertag" tag, I'm currently using:
NodeList labs = XMLInfo.getElementsByTagName("innertag1");
I'd like to be able to isolate any particular tag with ease. Theoretically, I could create many individual pages and simply change the values to "innertag2," "innertag3," etc., but this is obviously a bit impractical.
Is there a way to determine the value via a URL parameter? For instance, if I wanted to only display data from "innertag2," is there a way that the url http://www.server.com/data.jsp?id=innertag2 would adjust the tagname properly?
Thank you, any help would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以解析
document.location.href
并从中提取参数。这是来自我使用此技术的旧 HTML 文件(但是不确定它是否在所有浏览器上兼容)。You can parse
document.location.href
and extract parameters from there. This is from an old HTML file where I used this technique (not sure if it's compatible on all browsers, however).不确定这是否是您要查找的内容,但您可以使用
location.search
从网址访问参数。6502的答案几乎足够好了,它不是url解码参数。下面的函数更加精致(描述性变量名称,没有全局变量)
然后你可以这样做
Not sure if this is what you're looking for, but you can access parameters from the url using
location.search
.6502's answer is almost good enough, it's not url decoding parameters. The function below is a bit more polished (descriptive variable names, no global variables)
Then you could do