有没有办法链接到
具有唯一的“uri”属性?
我试图链接到网站中的特定段落,该网站已为每个段落添加了“uri”属性。即:
<p uri="/level1/leve2/pagename.p5">
有办法做到这一点吗?
(澄清一下,这不是一个我可以控制或可以改变的网站,除了建议他们改变之外,只是想知道是否有办法链接到他们目前的做法。)
I am trying to link to a specific paragraph in a website that has added a "uri" attribute to each of their paragraphs. ie.:
<p uri="/level1/leve2/pagename.p5">
Any way to do that?
(To clarify, this is not a site that I have any control over or can change beyond suggesting that they change, just wondering if there is a way to link to the way they currently do it.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不。它是一个非标准属性,浏览器不会对它执行任何操作。
如果你想链接到一个元素,那么你应该给它一个
id
并指定:理论上,你可以向页面添加一些JavaScript来搜索页面中的所有元素。带有
uri
属性并将它们转换为id
属性,但首先拥有一个真正的 HTML 文档会更好。如果您无法控制页面,那么如果不编写浏览器插件并让每个人都使用它,您就无法实现这一目标。
No. It is a non-standard attribute, browsers do nothing with it.
If you want to link to an element, then you should give it an
id
and specify:You could, in theory, add some JavaScript to the page that would search through all the elements in the page for ones with a
uri
attribute and convert them toid
attributes, but having a real HTML document in the first place would be better.If you have no control over the page then, short of writing a browser plugin and making everyone use it, you cannot achieve this.
使用 jQuery,您可以执行类似从
URI
$('p[uri]').attr('uri');
jsfiddle.net 示例中提取属性值的操作:
http://www.jsfiddle.net/vNtTs/
Using jQuery you could do something like pull the attribute value from
URI
$('p[uri]').attr('uri');
jsfiddle.net example here:
http://www.jsfiddle.net/vNtTs/
您可以使用自定义数据属性,如下所示:
如果您有多个
< /code> 那么最好给它一个唯一的 id。您可以使用 jQuery 来引用该属性,如下所示:
这将是完全合法的,并且大多数浏览器都支持自定义数据属性。
You could use custom data attributes, as such:
<p id="myId" data-uri="...">
If you have more than one
<p>
then it's best to give it a unique id. You can use jQuery to reference the attribute as such:And that would be perfectly legitimate and most browsers support custom data attributes.