在Span中查找文本并在警报中显示(Finding text within a Span and displaying in an alert)

编程入门 行业动态 更新时间:2024-10-27 22:27:05
在Span中查找文本并在警报中显示(Finding text within a Span and displaying in an alert)

在我当前的页面上,我目前有一个在iframe中呈现的范围:

<span id="SpanID_ctrlHelp_lblHelp">HelpText</span>

使用以下代码,我可以在警报中显示“HelpText”:

$('div[id*="MyControl"]').find("[id*='_fraDefaultFrame']") .contents() .each(function () { var txtBox = $('#SpanID_ctrlHelp_lblHelp').html(); alert(txtBox); });

上面的代码运行良好,但我想为给定屏幕上的每个帮助文本实例激活一个警报。 请注意,所有可用的帮助文本都有一个span ID,其中包含以下“_ctrlHelp_lblHelp”

希望有人能理解这一点并协助......

On my current page I currently have a span which is rendered within an iframe:

<span id="SpanID_ctrlHelp_lblHelp">HelpText</span>

With the below code I am able to display 'HelpText' within an alert:

$('div[id*="MyControl"]').find("[id*='_fraDefaultFrame']") .contents() .each(function () { var txtBox = $('#SpanID_ctrlHelp_lblHelp').html(); alert(txtBox); });

The above code works well however I would like to activate an alert for every instance of help text on a given screen. Note all available help text has a span ID which contains the following "_ctrlHelp_lblHelp"

Hope someone can make sense of this and assist...

最满意答案

这样做:

var txtBox = $('[id$="_ctrlHelp_lblHelp"]').html(); // id ends by

或这个:

var txtBox = $('[id*="_ctrlHelp_lblHelp"]').html(); // id contains

或者你可以试试这个:

$('[id$="_ctrlHelp_lblHelp"]').each(function(){ alert(this.innerHTML); });

This would do:

var txtBox = $('[id$="_ctrlHelp_lblHelp"]').html(); // id ends by

or this:

var txtBox = $('[id*="_ctrlHelp_lblHelp"]').html(); // id contains

Or you may try this:

$('[id$="_ctrlHelp_lblHelp"]').each(function(){ alert(this.innerHTML); });

更多推荐

本文发布于:2023-08-04 23:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1423105.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:并在   警报   文本   Span   alert

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!