DCSIMG
What is new in IE9 - HTML5 Selection APIs - שלמה גולדברג (הרב דוטנט)

שלמה גולדברג (הרב דוטנט)

מרצה בסלע ויועץ בעולם ה - net.

What is new in IE9 - HTML5 Selection APIs

כיצד אפשר לדעת מה הטקסט שהמשתמש כרגע בחר בשימוש עם HTML5

 
בהמשך לפוסטים על IE9 נראה הפעם כיצד בעזרת שימוש ב - HTML5 Selection APIs שהוגדר בתקן - ניתן לשלוף את הטקסט שהמשתמש בחר.
 
 
נניח שיש לנו את ה - html הבא
 

<div>

    Shlomo Goldberg -> What's new in IE9

</div>

<input type="text" id="myCtr" value="Shlomo Goldberg -> What's new in IE9" />

 

<input type="button" value="Select Window" onclick="selectdText()" />

<input type="button" value="Select Input" onclick="selctedTextInput()" />

 
כדי לקבל את הטקסט שהמשתמש בחר מתוך הדף (כלומר לא מ - input) נריץ את הקוד הבא
 

function selectdText() {

    alert(getSelection())

}

 
כדי לקבל את הקטסט שהמשתמש בחר בתוך input מסוג text, נריץ את הקוד הבא
 

function selctedTextInput() {

    var ctr = document.getElementById('myCtr');

    var selectedValue = ctr.value.substring(ctr.selectionStart, ctr.selectionEnd);

    alert(selectedValue);

}


תוכן התגובה

What is new in IE9 - HTML5 Selection APIs - ???????? ?????????????? (?????? ??????????) כתב/ה:

Pingback from  What is new in IE9 - HTML5 Selection APIs - ???????? ?????????????? (?????? ??????????)

# November 8, 2010 9:29 PM
שלח תגובה

(שדה חובה)  

(שדה חובה)  

(אופציונלי)

(שדה חובה) 

Please add 6 and 3 and type the answer here:


Enter the numbers above: