使用jquery提取标签之间的值并添加标题属性
我在动态生成的页面上有几个 a 标记,如下所示,
<a href='JavaScript:SWETargetGotoURL(vtUrl+"XRX+eCustomer+Account+Inventory+View", "_self")' id='s_ViewBar' name=s_ViewBar> Inventory </a>
我需要遍历其 href 标记中包含文本 "SWEtargetGotoURL" 的所有 a 标记,并根据 ,我需要添加标题标签
例如
if(extractedtext == " Inventory ")
title = "This is inventory homepage";
a 标签最终应该看起来像这样
<a href='JavaScript:SWETargetGotoURL(vtUrl+"XRX+eCustomer+Account+Inventory+View", "_self")' title = "This is inventory homepage" id='s_ViewBar' name=s_ViewBar> Inventory </a>
我使用以下代码来获取 href 标签中具有特定值的所有标签,但我无法获取中间的文本,我不知道如何运行循环并处理所有 a 标签
var screenName = $('a[href*="SWETargetGotoURL"]').attr('href');
非常感谢任何帮助。
I have several a tags as shown below on a dynamically generated page
<a href='JavaScript:SWETargetGotoURL(vtUrl+"XRX+eCustomer+Account+Inventory+View", "_self")' id='s_ViewBar' name=s_ViewBar> Inventory </a>
I need to traverse through all the a tags containing the text "SWETargetGotoURL" in their href tag and depending on the text I need to add the title tag
for example
if(extractedtext == " Inventory ")
title = "This is inventory homepage";
The a tag should finally look like this
<a href='JavaScript:SWETargetGotoURL(vtUrl+"XRX+eCustomer+Account+Inventory+View", "_self")' title = "This is inventory homepage" id='s_ViewBar' name=s_ViewBar> Inventory </a>
I used following code to get all the tags with specific value in href tag but I am unable to get the text in between and I don't know how to run a loop and work on all the a tags
var screenName = $('a[href*="SWETargetGotoURL"]').attr('href');
Any help is really appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您正在寻找的是 $.each ,它迭代选定元素的集合。
I think what you're looking for is $.each which iterates over the set of selected elements.