14 Temmuz 2009, Salı
Nasıl imleç sonu varlık doğal ses taşımak için
Şapka Gmail notlar widget gibi contenteditable
düğüm sonuna gitmek istiyorum.
StackOverflow konuları okudum, ama bu çözümler girdi kullanımına dayalı ve contenteditable
elemanları iş değil.
CEVAP
5 EKİM 2010, Salı
Geowa4 çözüm doğal ses öğesi için bir button için, ama işe yarayacaktır.
Bu çözüm, doğal ses bir öğenin sonuna kadar şapka taşımak için. Doğal ses desteği olan tüm tarayıcılarda çalışması gerekir.
function setEndOfContenteditable(contentEditableElement)
{
var range,selection;
if(document.createRange)//Firefox, Chrome, Opera, Safari, IE 9
{
range = document.createRange();//Create a range (a range is a like the selection but invisible)
range.selectNodeContents(contentEditableElement);//Select the entire contents of the element with the range
range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
selection = window.getSelection();//get the selection object (allows you to change selection)
selection.removeAllRanges();//remove any selections already made
selection.addRange(range);//make the range you have just created the visible selection
}
else if(document.selection)//IE 8 and lower
{
range = document.body.createTextRange();//Create a range (a range is a like the selection but invisible)
range.moveToElementText(contentEditableElement);//Select the entire contents of the element with the range
range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
range.select();//Select the range (make it the visible selection
}
}
Koda benzer bir kod kullanılabilir:
elem = document.getElementById('txt1');//This is the element that you want to move the caret to the end of
setEndOfContenteditable(elem);
Bunu Paylaş:
Nasıl Vim imleç hareket etmeden ekrana...
Nasıl şapka işareti(imleç) doğal ses e...
Nasıl başka bir eleman içine bir öğe t...
Nasıl (dişliler) varlık boru hattı ile...
Nasıl bir git repo (klon değil) dosyal...