简体   繁体   English

使用 JavaScript 在 HTML 页面中的文本选择中获取多个跨度标签

[英]Get multiple Span Tags inside the selection of Text in a HTML Page using JavaScript

I needed to get all the element ids within the selection range.我需要获取选择范围内的所有元素 ID。

For example,例如,

Start the work开始工作

If i selected the "Start" and "the" together i am only getting element id of "Start" using getelementbyselectionrange in javascript.如果我同时选择了“开始”和“该”,我只会在 javascript 中使用 getelementbyselectionrange 获取“开始”的元素 ID。 How to get the array of span id's in the selection sentence.如何在选择语句中获取 span id 的数组。

I am trying this example in uiwebview in iphone, How to achieve this using javascript?我在 iphone 的 uiwebview 中尝试这个例子,如何使用 javascript 来实现这个?

I got the jquery example in this site: http://jsfiddle.net/KC48j/17/ But it is not helping me?我在此站点中获得了 jquery 示例: http://jsfiddle.net/KC48j/17/但它对我没有帮助吗?

Help me in this issue帮我解决这个问题

Can you clarify "start the work".你能澄清“开始工作”吗? I'm not sure based on your description if the HTML of that sentence is:根据您的描述,我不确定该句子的 HTML 是否为:

<div id="d1"><span id="s1">start</span><span id="s2">the</span><span id="s3">work</span></div>

If that's the case, then you can use YUI's getElementsBy function in it's DOM package and make sure you specify the div id d1 as the root and the tag to be span .如果是这种情况,那么您可以在它的 DOM package 中使用 YUI 的getElementsBy function 并确保将 div id d1指定为root ,并将tag指定为span This will return back an array of span DOM elements within that div that you can loop on.这将返回一个可以循环的 div 中的 span DOM 元素数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM