我可以通过以下方式获取所选字符串值,
if(!window.Kolich){
Kolich = {};
}
Kolich.Selector = {};
Kolich.Selector.getSelected = function(){
var t = '';
if(window.getSelection){
t = window.getSelection();
}
return t;
}
Kolich.Selector.mouseup = function(){
var st = Kolich.Selector.getSelected();
// alert(typeof(st)) //showing object
var data = st.toString();
data.strike();
}
但我需要对所选字符串应用strike()方法。
答案 0 :(得分:0)
请尝试使用DOM Range
strike()
方法,而不是使用surroundContents()
方法。
if(!window.Kolich){
Kolich = {};
}
Kolich.Selector = {};
Kolich.Selector.getSelected = function(){
var t = '';
if(window.getSelection){
t = window.getSelection();
}
return t;
}
Kolich.Selector.mouseup = function(){
var st = Kolich.Selector.getSelected();
// alert(typeof(st)) //showing object
//var data = st.toString();
var range = st.getRangeAt(0);
var strike = document.createElement("strike");
range.surroundContents(strike);
}