[英]How to replace anchor text inside aps.net label?
How to Replace anchor tag inner text inside of Asp.net label: 如何替换Asp.net标签内的锚标签内部文本:
For Example : 例如 :
<asp:Label ID="AER_UI_Exam_MPN_ThreeAttemptsBefore_1" runat="server" Text="Please visist: <a id='google'class='translatetext lblfont' href='https://google.com' target='_blank' style="font-size: 12px;">google</a>" CssClass="lblfont translatetext" Style="font-size: 12px;" />
if I will get the id based on class 如果我将根据课程获得id
$(".translatetext").each(function () {
var id = this.id;
dictionary[id] = $("#" + id + "")[0].innerText;
});
I am getting both the id but anchor tag is replacing as text not as link. 我得到了两个id但是锚标签正在替换为文本而不是链接。 here while debug I found the that for first id -innertext is: Please visist:google
, when this inner text is replacing with 在这里调试我发现第一个id -innertext是: Please visist:google
,当这个内部文本被替换为
"some text"
the second id is not found for anchor
. 找不到anchor
的第二个id。 how to handle this scenario? 如何处理这种情况?
Result is: Please visist:google, 结果是:请访问:google,
Expected Result: :Please visist:[google] 预期结果:请访问:[google]
Hi please try this. 嗨,请试试这个。
<asp:Label ID="AER_UI_Exam_MPN_ThreeAttemptsBefore_1" runat="server" CssClass="lblfont translatetext"
Style="font-size: 12px;"> Please visist: <a id='google'class='translatetext lblfont' href='https://google.com' target='_blank' style="font-size: 12px;">google</a></asp:Label>
Edited : 编辑:
First you build the anchor tag in Jquery. 首先,在Jquery中构建锚标记。 Like this. 像这样。
var myhtml="Please visist: <a id='google' class='translatetext lblfont' href='https://google.com'
target='_blank' style='font-size: 12px;'>"+some text+"</a>";
then assign the above variable to that label. 然后将上述变量分配给该标签。
$("#AER_UI_Exam_MPN_ThreeAttemptsBefore_1").html(myhtml);
If you wwant to wrap the text with square bracket, use like this, 如果您想用方括号包装文本,请像这样使用,
$(".translatetext").each(function() {
$(this).text("[" + $(this).text() + "]");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.