使用jQuery突出显示(选择)文本框中的所有文本 [英] Using jQuery to Highlight (Select) All Text in a Textbox

查看:102
本文介绍了使用jQuery突出显示(选择)文本框中的所有文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入文本框,其中包含一些文本,onclick事件我想运行一个javascript函数来选择(突出显示)这个框中的所有文本,我如何使用jquery做到这一点?

I have an input text box with some text in it , onclick event I want to run a javascript function to select (highlight) all text that is in this box , how I can do that with jquery?

推荐答案

您可以查看

You may take a look at this article:


假设我们有以下文本输入:

Let's assume that we have the following text input:

<input type="text" id="txtInput" />

在大多数情况下,我们希望将此功能提供给我们所有的
文本框网站,所以我们将创建一个函数来处理
this,并根据需要调用它。使用期望的
参数调用此函数将使执行文本的高亮显示。

In most cases, we would want to have this feature available to all textboxes across our website, so we would create a function to handle this, and call it as needed. Calling this function with the expected argument will make execute the highlighting of the text.

function selectAllText(textbox) {
textbox.focus();
textbox.select(); }

假设您正在开发DotNetNuke 5,或者已经将jQuery导入到您的网站中,请添加以下内容jQuery到您的网站的每个文本框。 (如果你有很多文本框,我们可以做不同的事情,但这是另一个帖子。)

Assuming you are developing against DotNetNuke 5, or have jQuery already imported into your website, add the following jQuery to your site for each textbox. (If you have a lot of textboxes, we could do this differently, but that's for a different post.)

jQuery('#txtInput').click(function() { selectAllText(jQuery(this)) });


这篇关于使用jQuery突出显示(选择)文本框中的所有文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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