我试图提醒我从 CKEDITOR 中的 textarea 中选择的选项。当我跑的时候,就"No text is selected."
出来了。我想看到"The current selection is: "+ selection.
我认为我需要在这里更改的警报 vartextarea = document.getElementById('editor1');
有人可以帮我解决这个问题吗?
设置:
function ()
{
var selection = "";
var textarea = document.getElementById('editor1');
if ('selectionStart' in textarea)
{
// check whether some text is selected in the textarea
if (textarea.selectionStart != textarea.selectionEnd)
{
selection = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
}
}
else
{
// Internet Explorer before version 9
// create a range from the current selection
var textRange = document.selection.createRange();
// check whether the selection is within the textarea
var rangeParent = textRange.parentElement();
if (rangeParent === textarea)
{
selection = textRange.text;
}
}
if (selection == "")
{
alert("No text is selected.");
}
else
{
alert("The current selection is: " + selection);
}
}