简体   繁体   English

Javascript文本框onkeyup事件

[英]Javascript textbox onkeyup event

Html: HTML:

<asp:TextBox ID="phone" " runat="server" AutoCompleteType="Disabled" onkeyup="this.value=this.value.EditPhone()"></asp:TextBox>

Javascript: 使用Javascript:

 String.prototype.EditPhone= function () {

 var str = document.getElementById('phone').value;
        if (str.substring(0, 1) == "0") // If first value is "0" remove it
            str = str.substring(1, str.length);

        return str;
    };

I remove if first string value is "0" . 如果第一个字符串值为“ 0”,则删除。

After that I enter phone number 5552221133 etc.. 之后,我输入电话号码5552221133等。

If i change 11 to 44 i can not remove/change 11 and write new value(44) because of onkeyup value. 如果我将11更改为44,则由于onkeyup值,我无法删除/更改11并写入新值(44)。

If i return null it is not working again. 如果我返回null,则无法再使用。 How can i remove/change text according to my code ? 如何根据我的代码删除/更改文本?

我有

<asp:TextBox ID="phone" " runat="server" AutoCompleteType="Disabled" onkeyup="this.value=this.value.EditPhone()"></asp:TextBox>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM