在JavaScript中改变文本框的文本 [英] Change textbox text in JavaScript

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

问题描述

我允许用户以使用两个文本框之一来搜索数据库 - 一个是ID字段,和一个是自由文本字段。我使用ASP.NET与C#BTW。

I'm allowing a user to use either one of two textboxes to search a database - one is an ID field, and one is a freetext field. I'm using ASP.NET with C# btw.

不管怎样,我需要做的是这么当的一个文本框,用户点击,其他的文本框中的文本被简单地删除,所以其他的文本框为空。

Anyway, all I need to do is have it so when a user clicks on one of the text boxes, the other text box text is simply deleted, so the other text box is blank.

我会怎么做呢?我猜JavaScript是一种解决方案。

How would I do this? I'm guessing JavaScript is the solution.

推荐答案

由于在JavaScript函数:

Given a function in javascript:

function clearOther(which){
 document.getElementById(which).value='';
}

当你专注于一个文本框,这个可以被调用,通过对方的ID:

this can then be called when you focus on one textbox, passing the id of the other:

<input type="text" id="box1" onfocus="clearOther('box2')" />
<input type="text" id="box2" onfocus="clearOther('box1')"  />

工作的例子 - > http://jsfiddle.net/CwWKn/

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

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