Check the value in textbox is selected using jquery
Possible Duplicate:
Check checkbox checked property using jQuery
Can anyone let me know how to check the value is selected in the html textbox using jquery. For example the value in the textbox if selected the text is slected with blue background.
See this : http://jsfiddle.net/rT5vR/
var t = '';
if(window.getSelection) {
t = window.getSelection();
} else if(document.getSelection) {
t = document.getSelection();
} else if(document.selection) {
t = document.selection.createRange().text;
}
return t;
}
$("#myElement").select(function(eventObject) {
alert(getSelected().toString());
});
Or
$('#myElement').select(function(e) {
var start = e.target.selectionStart;
var end = e.target.selectionEnd;
alert($('#myElement').val().substring(start, end));
});
The second one is perfect. Don't know how much cross-browser the first one is...
链接地址: http://www.djcxy.com/p/9520.html上一篇: 检查复选框是否被选中?
下一篇: 检查文本框中的值是使用jquery选择的