如何在MVC Razor中使用Javascript创建动态强类型文本框? [英] How to Create Dynamic Strongly Typed Text Boxes using Javascript in MVC Razor?

查看:135
本文介绍了如何在MVC Razor中使用Javascript创建动态强类型文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MVC View中创建强类型动态文本框。我已经从Jquery创建动态控件但不知道如何使其强烈打字???





请帮帮我伙计们.. 。提前谢谢。

解决方案

根据定义,你不能得到像JavaScript这样的强类型。它基于一个非常不同的范例,宽松的打字,更准确地说,动态 duck

http://en.wikipedia.org/wiki/JavaScript [ ^ ],

http://en.wikipedia.org/wiki/Dynamic_typing [ ^ ],

http://en.wikipedia.org/wiki/Duck_typing [ ^ ]。



事实上,JavaScript中只有9种不同的类型,其中只有一种与文本框相关:

https://developer.mozilla.org/en-US/doc s / Web / JavaScript / Reference / Operators / typeof [ ^ ]。



如果比较构造函数对象的对象。



有关此想法的详细信息,请参阅我过去的答案:

此代码是否正确? [ ^ ],

这是怎么发生的? Js [ ^ ],

这是哪种数据类型 [ ^ ] 。



鉴于此,强类型文本框无关紧要。您所需要的只是通过过滤掉字符输入来强制键入某些文本框内容。这里有详细解释: http://www.javascripter.net/faq/keyboardinputfiltering.htm [< a href =http://www.javascripter.net/faq/keyboardinputfiltering.htmtarget =_ blanktitle =New Window> ^ ]。



另一种方法是使用一些 MaskedTextBox ,或者在即将使用数据时进行验证,或者使用组合。



如果你想用JavaScript做一些严格打字的路线,首先要检查你的方法的完整性。请阅读: http://davidwalsh.name/javascript-objects-distractions [ ^ ]。



- SA

I want to create Strongly typed Dynamic Text Boxes in MVC View. i have already create dynamic controls from Jquery but dont know how to make it strongly typed???


Please help me Guys...Thanks in advance.

解决方案

By definition, you cannot get anything like strong typing with JavaScript. It is based on a very different paradigm, loose typing, more exactly, dynamic and duck:
http://en.wikipedia.org/wiki/JavaScript[^],
http://en.wikipedia.org/wiki/Dynamic_typing[^],
http://en.wikipedia.org/wiki/Duck_typing[^].

As a matter of fact, there are only 9 distinct types in JavaScript, and only one of them is relevant to text boxes:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof[^].

You can create some pale imitation of strict typing if you compare the constructor objects of the objects.

For the detail on this idea, please see my past answers:
Is this code correct?[^],
WHy does this happen? Js[^],
which datatype is this[^].

In view of that, the "strongly typed text boxes" is something irrelevant. All you need is to enforce typing of some text box content by filtering out the characters typing. This is explained in detail here: http://www.javascripter.net/faq/keyboardinputfiltering.htm[^].

Another approach would be using some MaskedTextBox, or validation when the data is about to be used, or the combination.

If you want to take some "strict typing" route with JavaScript, first examine the sanity of your approach. Please read this: http://davidwalsh.name/javascript-objects-distractions[^].

—SA


这篇关于如何在MVC Razor中使用Javascript创建动态强类型文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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