文章源自:http://viralpatel.net/blogs/change-form-input-textbox-style-focus-jquery/
Changing Form Input (Textbox) Style on Focus using jQuery
User experience has always been a factor to be consider while you design a website. Lot of fields such as Human Computer Interface (HCI) and Usability etc have been studied upon. While designing a user interface, special care should always been taken while placing the text fields and selecting fonts. While lot of web designers prefer to display forms in plain vanilla manner, lot of others prefer to give user as much help while filling the forms. Thus the html forms should always have description field with each input field. Also if we can highlight the field that user is filling, it can improve the user experience.
Thus How can we implement the feature where the Input fields which are currently focused are highlighted?
Let us use jQuery and create a simple feature on a HTML Form.
Step 1: The HTML Code
We will use following form as a sample HTML Form and apply the Focus effect using jQuery.
<FORM id="sample"> <TABLE> <TR> <TD>Name </TD> <TD><INPUT type="text"/></TD> </TR> <TR> <TD>Age</TD> <TD><INPUT type="text"/></TD> </TR> <TR> <TD>Phone no.</TD> <TD><INPUT type="text"/></TD> </TR> </TABLE> </FORM>
Step 2: The CSS Stylesheet
We will use a simple style class to apply to the focused field.
.focus { border: 2px solid #AA88FF; background-color: #FFEEAA; }
Step 3: Add the effect using jQuery
We will use jQuery to add effect to the form elements. Two events has to be taken care of. While the input field is focused and while the focus is moved to next textbox (blured).
$('input[type="text"]').focus(function() { $(this).addClass("focus"); }); $('input[type="text"]').blur(function() { $(this).removeClass("focus"); });
相关推荐
在使用UasyUI的时候,在一般的input输入框上添加class="easyui-textbox"属性,则在该输入框上添加的事件将不起作用,但是如果去掉class="easyui-textbox"变成一般的input则起作用。 控件的生成原理,它是把你原有的...
"Add Textbox Dynamically using jQuery.zip"这个压缩包中的示例,主要展示了如何利用jQuery在用户交互时动态创建一个新的文本输入框。 首先,jQuery库是一个强大的JavaScript库,它简化了DOM操作、事件处理、动画...
在这个"Drag and Drop Inserting Text to Input Textbox with jQuery"的项目中,我们关注的是如何利用jQuery库来实现这一功能,特别是在输入文本框中插入拖放文本的场景。jQuery是一个流行的JavaScript库,它简化了...
3. **让textBox获得焦点**:最后调用textBox的`Focus()`方法。 #### 示例2:调整控件属性 ```csharp // 确保textBox可见且可用 this.txtReceiveMoney.Visible = true; this.txtReceiveMoney.Enabled = true; // ...
<input id="textbox" class="easyui-textbox" onchange="handleTextboxChange(this)"> <label>Combobox: <option value="Option1">Option1 <option value="Option2">Option2 <option value="Option3">...
/// 从FORM2的TEXTBOX值设置到FORM1 TEXTBOX的值 /// /// <param name="Value"></param> private void SetTextBoxValue(string Value) { textBox1.Text = Value; } private void button1_Click(object ...
本教程将详细讲解如何使用TextBox结合Jquery的WdatePicker插件实现一个方便快捷的日期选择器。 首先,`TextBox`是ASP.NET中的一个控件,用于创建用户可以输入文本的HTML元素。在JavaScript中,我们可以对这个控件...
document.getElementById('<%= TextBox1.ClientID %>').addEventListener('focus', function() { // 在这里添加你希望在TextBox获得焦点时执行的代码 }); ``` 2. `blur`事件:当TextBox失去焦点,即用户离开文本框...
我们可以通过在文本框的data-options中指定events属性来绑定blur事件,如:<input class="easyui-textbox" data-options="events:{blur:getStaffno}" id="staffno"name="staffno" value="${user.staffno}"/> ...
在Windows Forms开发中,TextBox控件是最常用的输入控件之一,用于显示和接收文本输入。然而,系统默认的TextBox控件并不支持文字的垂直居中显示。为了满足这个需求,我们可以自定义一个控件,继承自TextBox类,并...
textBox1.Focus(); } } private void textBox1_GotFocus(object sender, EventArgs e) { // 在这里执行获得焦点时的操作,例如清除默认文本 if (textBox1.Text == "请输入内容...") { textBox1.Text = ""; }...
本主题将深入探讨如何在两个独立的窗体之间有效地传递数据,以实现Form1的TextBox控件值传递到Form2,以及Form2的TextBox控件值回传给Form1。 首先,让我们了解Form1向Form2传递值的基本步骤: 1. **创建Form2对象...
`TextBoxInput`是处理用户在`TextBox`中输入数据的典型应用场景。在C#中,我们通常会为`TextBox`设置`TextChanged`事件,以便在用户输入时实时检查数据的合法性。例如,我们可以验证用户是否输入了有效的邮箱地址、...
<Style TargetType="TextBox"> <ControlTemplate TargetType="TextBox"> ,0,0,1"> </Style> ``` 在这个样式中,我们设置了Border的`BorderThickness`为`0,0,0,1`,这意味...
textbox.Focus(); } else if (textbox.TextLength > length) { errorProvider1.SetError(textbox, "请输入小于" + length.ToString() + "个字符的" + controlName + "!"); textbox.SelectAll(); textbox....
本DEMO "TestForm(label和textbox组合控件)" 是一个关于自定义控件的学习实例,旨在帮助开发者理解如何在C#中创建和使用自定义控件。在Windows Forms应用程序中,我们经常使用Label和TextBox控件来显示信息和接收...
### Form2调用Form1控件的解决方案 #### 背景与问题描述 在Windows Forms应用程序开发过程中,经常会遇到需要在不同的窗体之间进行交互的情况。例如,当用户在`Form1`上的一个按钮(假设为`Button1`)被点击时,会...
如验证input或textbox中输入的时候email只需: <input type="text" ValidDataForEmail='default' /> 在input或textbox中加入属性ValidDataForEmail='default'即刻实现email的验证操作 还有 网址、数字、身份证、日期...
在本文中,我们将讨论如何在WindowsForm中实现TextBox的占位符(Placeholder)提示功能。 首先,我们可以利用Windows API中的`SendMessage`函数来发送`EM_SETCUEBANNER`消息,这是一种系统级别的方法,可以直接操作...
在C#编程中,开发Windows桌面应用程序时,我们经常需要处理用户输入的数据,例如通过TextBox控件获取用户的数字输入,并进行一些计算操作。本话题主要关注如何实现多个TextBox中的数值相加,然后将结果实时显示在另...