选择了哪个文本框文本 [英] which textbox text is selected

查看:55
本文介绍了选择了哪个文本框文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有将项目模板作为文本框的数据列表控件...用户在文本框中输入值,然后在任何文本框中选择特定文本....如何在Java脚本中获取选定的文本

I have Datalist control with item template as textbox...user enter the values in textboxes then select particular text in any of textbox....how get the selected text in java script

推荐答案

尝试一下
function isTextSelected(input) {
    if (typeof input.selectionStart == "number") {
        return input.selectionStart == 0 && input.selectionEnd == input.value.length;
    } else if (typeof document.selection != "undefined") {
        input.focus();
        return document.selection.createRange().text == input.value;
    }
}


与此


with this

<input type="text" id="test" value="Some text">
<input type="button" onmousedown="alert(isTextSelected(document.getElementById('test')));" value="Selected?">


选择特定文本意味着什么?你能解释一下吗?
select particular text means what ? can u explain it ?


这篇关于选择了哪个文本框文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆