2017-05-22 26 views
0

我有一個文本元素,並且我想要通過僅鼠標突出顯示的選擇部分,因此可以說用戶在文本框中寫入123456798,然後選擇456用鼠標,我想得到456,我該怎麼做?角庫爲我提供了一些東西嗎?找不到方法。 這是我完整的html代碼部分。如何在角度javascript文本框中獲取highligted(模糊)區域

其實我進入,但需要刪除第一個和最後<>字符

<input type="text" id="dialpadText" call-from-dialpad="startAudioCall()" 
     ng-model="dialpadText" 
     ng-change="dialpadTextEntered()" 
     placeholder="Enter a name or number" autofocus="" 
     class="ng-valid ng-touched ng-dirty ng-valid-parse ng-modified"> 
+0

http://blog.sodhanalibrary.com/2016/10/ get-highlightselected-text-using.html –

+0

[JavaScript從頁面上的任何textinput/textarea獲取選定文本]的可能重複(http://stackoverflow.com/questions/6416020/javascript-get-selected-text-from- any-textinput-textarea-on-the-page) –

回答

0

如果我明白你的問題正確,那麼你想要得到或警告鼠標選擇中的突出價值,對不對?如果是這樣,那麼這裏就是解決方案,只需藉助JavaScript,就可以提醒文本部分的選定值:

<input type="text" onBlur = "getSelectionText()"> 
<script> 
function getSelectionText(){ 
var selectedText = "" 
if (window.getSelection){ // all modern browsers and IE9+ 
alert(window.getSelection()); //it will alert the selected value 
} 
} 
</script> 
+0

其實我不需要這個問題的答案了,但我的帳戶被禁止了,並且我被要求編輯和改進我以前的所有帖子,無論如何。 –