开发者

Anyone know how to get the offset of a character at a given position of its parent tag?

开发者_Python百科

friends.I'd like to do something like this: A DIV in a web page contains some text,for example ,Hi,hello world ,and the position(100,100) of the page point to the char 'e'.I do not need which char it is but the offset of it,which means the place that 'e' stands in the whole sentense 'Hi,hello world'(Which is the content of its parent tag DIV).In this example,the offset is 4. 'H' for 1,'i' for 2,','for 3 and so forth.

Any one can help me?


An example:

var my_car="Ferrari";
var where_is_a=my_car.indexOf('a');
alert('The a is at position '+where_is_a+'.');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜