如果已更改其他文本框值,如何清除文本框 [英] How to clear a text box if the other textbox value has been changed

查看:86
本文介绍了如果已更改其他文本框值,如何清除文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



说我3个文本框,名为val1,val2和res。我在res中显示val1和val2中值的加法结果。因此,如果用户更改这些值(i-e val1和val2中存在的值),则应清除res。示例用户在val1中输入2,在val2中输入3,因此添加结果为5,显示在红色文本框中现在说现在用户决定更改val1中的值,因此当他开始更改时,我希望我的res文本框被清除。



初学者请原谅我的平均问题



非常感谢

解决方案

您是否尝试过实现 TextChanged [ ^ ]事件在 val1 val2 文本框?如果您只需要在用户向其他两个文本框输入内容时清除 res ,只需在此处理程序中写入:



 res.Text =  string  .Empty; 


< blockquote>这是一个选项,在客户端使用javascript的onkeyup事件来清除结果。当用户选择val1控件并按下并释放键时,结果值将设置为空字符串。

  <   script     type   =  text / javascript >  
// 结果清晰
函数 ResetResultValue(){
var el = document .getElementById(' <%= res.ClientID%>');
el.value = ' ';
}
< / 脚本 >

< asp:textbox id = val1 runat = server onkeyup = javascript:ResetResultValue(); > < / asp:textbox >
< asp:textbox id = val2 runat = 服务器 > < / asp:textbox >
< asp:textbox < span class =code-attribute> id = res runat = 服务器 > < / asp:textbox >
< asp:按钮 id = btnSubmit runat = server text = 提交 onclick = btnSubmit_Click / > < /跨度>


Hello

Say i 3 textboxes, the are named val1 , val2 and res. I show the addition result of values in val1 and val2 in res. So, if a user alters these values(i-e the values present in val1 and val2) res should be cleared. Example user enterd 2 in val1 and 3 in val2 so the addition result is 5 which is being shown in red textbox now say now user decides to change the value in val1 so when he begins to change i want my res text box to be cleared.

Beginner so please pardon my average questions

Thanks anyways

解决方案

Have you tried implementing a handler of TextChanged[^] event on val1 and val2 textboxes? If you simply need res to be cleared when user inputs something into any of two other textboxes, just write in this handler:

res.Text = string.Empty;


Here's one option, use javascript's onkeyup event on the client side to clear the result. When the user selects the val1 control and presses and releases a key the result value will be set to an empty string.

<script type="text/javascript">
    // clear result
    function ResetResultValue() {
        var el = document.getElementById('<%= res.ClientID %>');
        el.value = '';
    }
</script>
    
<asp:textbox id="val1" runat="server" onkeyup="javascript:ResetResultValue();"></asp:textbox>
<asp:textbox id="val2" runat="server"></asp:textbox>
<asp:textbox id="res" runat="server"></asp:textbox>
<asp:button id="btnSubmit" runat="server" text="Submit" onclick="btnSubmit_Click" />


这篇关于如果已更改其他文本框值,如何清除文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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