jquery输入掩码用asp.net覆盖文本框值

时间:2022-12-02 11:37:58

I have an ASP.NET web form, and I'm using the masked input plugin from http://digitalbush.com/projects/masked-input-plugin, which seems to be a pretty popular plugin. It works very well, but I'm having an issue when attempting to pre-populate a value in a textbox using the masking.

我有一个ASP.NET Web表单,我正在使用来自http://digitalbush.com/projects/masked-input-plugin的屏蔽输入插件,这似乎是一个非常受欢迎的插件。它工作得很好,但是在尝试使用屏蔽预先填充文本框中的值时遇到问题。

In my document.ready, Im performing:

在我的文件中,我正在表演:

$("#txtPrimaryPhone").mask("(999) 999-9999 ?x9999");

In my codebehind I set my text property like so:

在我的代码隐藏中,我设置了我的文本属性,如下所示:

txtPrimaryPhone.Text = "1234567890";

When my page loads, my textbox is empty. Has anyone run into similar issues, or can anyone offer any suggestions? Thanks!

当我的页面加载时,我的文本框是空的。有没有人遇到类似的问题,或者任何人都可以提出任何建议?谢谢!

2 个解决方案

#1


1  

Here's the solution :

这是解决方案:

Instead of

代替

$("#txtPrimaryPhone").mask("(999) 999-9999 ?x9999");

Try this

尝试这个

 $.each($('#txtPrimaryPhone'), function (iEmt, emt) {
            $(emt).mask("(999) 999-9999 ?x9999").val($(emt).attr("value"));
        });

it works for me :)

这个对我有用 :)

#2


0  

If I’m correct, the jQuery mask is applied once you load your page, then your txtPrimaryPhone.Text is set server side. I have two theories.

如果我是正确的,一旦你加载页面就应用jQuery掩码,然后你的txtPrimaryPhone.Text设置为服务器端。我有两个理论。

One: 1234567890 is not accepted by the mask because it is not in the right format. Right format should be something like txtPrimaryPhone.Text = “(999) 999-9999 x99999”;.

一:面具不接受1234567890,因为它的格式不正确。正确的格式应该类似于txtPrimaryPhone.Text =“(999)999-9999 x99999”;

Two: The mask works as a filter for user input but does not accept the server side value for txtPrimaryPhone. It’s a little hard to find out without a sample we can debug or edit.

二:掩码用作用户输入的过滤器,但不接受txtPrimaryPhone的服务器端值。没有我们可以调试或编辑的样本,有点难以找到。

#1


1  

Here's the solution :

这是解决方案:

Instead of

代替

$("#txtPrimaryPhone").mask("(999) 999-9999 ?x9999");

Try this

尝试这个

 $.each($('#txtPrimaryPhone'), function (iEmt, emt) {
            $(emt).mask("(999) 999-9999 ?x9999").val($(emt).attr("value"));
        });

it works for me :)

这个对我有用 :)

#2


0  

If I’m correct, the jQuery mask is applied once you load your page, then your txtPrimaryPhone.Text is set server side. I have two theories.

如果我是正确的,一旦你加载页面就应用jQuery掩码,然后你的txtPrimaryPhone.Text设置为服务器端。我有两个理论。

One: 1234567890 is not accepted by the mask because it is not in the right format. Right format should be something like txtPrimaryPhone.Text = “(999) 999-9999 x99999”;.

一:面具不接受1234567890,因为它的格式不正确。正确的格式应该类似于txtPrimaryPhone.Text =“(999)999-9999 x99999”;

Two: The mask works as a filter for user input but does not accept the server side value for txtPrimaryPhone. It’s a little hard to find out without a sample we can debug or edit.

二:掩码用作用户输入的过滤器,但不接受txtPrimaryPhone的服务器端值。没有我们可以调试或编辑的样本,有点难以找到。