English 中文(简体)
G. 目前选用的网页
原标题:Get currently selected text on page

你们如何在文本中找到目前选定的案文(并修改案文)?

我看到了可以听取意见的选定活动,但我很想知道,是否找到了目前选定的案文。

另外,为了能够修改案文中这一具体部分,你需要使用哪些技术? 我以某种方式认为,选择的立场属于整个案文的内容?

我希望能够做的是选择和修改,或者把选择归结到某些标签上,就像你能够做的那样。

最佳回答

我把我认为在所有浏览器(包括E < 9)中这样做的明确职能多次张贴在Stack Overflow上。 例如:

https://stackoverflow.com/questions/3622818/ies-document-selection-createrange-doesnt-include-leading-or-trailing-blank-lin/3648244#3648244>IE s document.selection.createRange don t include leading or踪迹ing blank Line

I d also recommend my jQuery plug-in for this, which includes this function and others to insert, delete, surround or replace the selected text, which sounds like exactly what you want. It s also the only jQuery plug-in for textarea selections I m aware of that works correctly with line breaks in IE < 9.

问题回答

如果你只得支持最新的浏览器,你可以使用<条码>选择标准<>和<条码>选择/代码>,从而暴露了文本领域所选案文的性质立场。 你可以只修改选定的案文,但更新了你可以使用的<条码>>选择Range,以重选案文。

From this page

http://www.netadmintools.com/art466.html

function display(txtarea) {
  var sl = (txtarea.value)
     .substring(txtarea.selectionStart, txtarea.selectionEnd);        
} 


<body onload="thisForm=document.frmKey;">

jquery field selection plugin.. Download Here examples on site.

The ::selection selector might work as well. http://www.w3schools.com/cssref/sel_selection.asp





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签