开发者

Is there a way to update the dom without effecting the Mouse Cursor?

For example, I'm using the following function:

$('body').html( function(i,html) {
    var arr = html.split(". ");
    arr[arr.length-1]="<span class='findme' >"+arr[arr.length-1]+"</span>&nbsp;";
    alert(arr)
    return arr.join(". "开发者_Python百科);
});

The problem is it moves the cursor away from where the user was typing. Has anyone else seen this?


By setting the HTML of any element you're essentially resetting all of its content! All event handlers, all states and DOM properties, and this includes any element that currently has 'focus'.

Use the DOM API as it was intended.

It looks like you want to wrap the content following the last period in the page with a <span>. To do this properly you'd need to traverse through the DOM checking for text-nodes that contain the period and then replace part of the last-found text node with a <span> element.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜