-
Fototrend
JavaScript != Java (A JavaScript nem összekeverendő a Javával, két különböző programozási nyelvről van szó!)
Új hozzászólás Aktív témák
-
tildy
nagyúr
válasz
puttputt
#1438
üzenetére
Ez nagyon jó, de kicsit átírtam.
function surroundText( textarea , text)
{
// Can a text range be created?
if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
{
var caretPos = textarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? '<' + text + '>' + caretPos.text + '</' + text + '> ' : '<' + text + '>' + caretPos.text + '</' + text + '>';
caretPos.select();
}
// Mozilla text range wrap.
else if (typeof(textarea.selectionStart) != "undefined")
{
var begin = textarea.value.substr(0, textarea.selectionStart);
var selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart);
var end = textarea.value.substr(textarea.selectionEnd);
var newCursorPos = textarea.selectionStart;
var scrollPos = textarea.scrollTop;
textarea.value = begin + '<' + text + '>' + selection + '</' + text + '>' + end;
if (textarea.setSelectionRange)
{
if (selection.length == 0)
textarea.setSelectionRange(newCursorPos + text.length + 2 , newCursorPos + text.length + 2);
else
textarea.setSelectionRange(newCursorPos, newCursorPos + text.length + selection.length + text.length + 2 + 3 );
textarea.focus();
}
textarea.scrollTop = scrollPos;
}
// Just put them on the end, then.
else
{
textarea.value += '<' + text + '>' + '</' + text + '>';
textarea.focus(textarea.value.length - 1);
}
}
Új hozzászólás Aktív témák
- BESZÁMÍTÁS! MSI GF63 Thin 10SC Gamer - i5 10500H 16GB DDR4 1TB SSD GTX 1650 4GB Max-Q W11
- GYÖNYÖRŰ iPhone 13 mini 128GB Midnight -1 ÉV GARANCIA - Kártyafüggetlen, MS4077
- ÚJ Lenovo Yoga 7 - 14" WUXGA OLED Érintő - Ryzen AI 5 340 - 16GB - 512GB - Win11 - 4 év garancia
- Apple iPhone 15 Pro 256GB, Kártyafüggetlen, 1 Év Garanciával
- ÚJ! 32GB (2x16GB) Kingston DDR5 5600MT/s RAM készlet Bontatlan
Állásajánlatok
Cég: Laptopszaki Kft.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest

