简体   繁体   English

如何在电话验证方案中使用dojo.destroy和dojo.create?

[英]How can I use dojo.destroy and dojo.create in a phone validation scenario?

I have a problem where I have a phone input field that is connected to a dojo dropdown widget. 我有一个电话输入字段连接到dojo下拉小部件的问题。 You can select a US phone type or a International phone type. 您可以选择美国电话类型或国际电话类型。 If you select the Us type you can only enter 10 characters in the input field. 如果选择美国类型,则只能在输入字段中输入10个字符。 If you select the International type you can put 15 characters in the input field. 如果选择国际类型,则可以在输入字段中输入15个字符。 This is working correctly in Firefox and Internet Explorer 8 but not working correctly in Internet explorer 7. 这在Firefox和Internet Explorer 8中正常运行,但在Internet Explorer 7中无法正常运行。

here is the html code: 这是html代码:

<input id="tPhone" type="text" name="tPhone" class="isCompleted phone-number" tabindex="0" maxlength="10" rel="i13"/>

I figure I can get it working right in dojo if I dynamically alter or destroy the dom node and replace it based on the selection the user makes. 我认为,如果我动态更改或破坏dom节点并根据用户的选择替换它,则可以在dojo中使其正常工作。 How can I do this with dojo? 我如何用dojo做到这一点? Here is my dojo code that I have now: 这是我现在拥有的dojo代码:

this.phoneTypeDrop = new widget.StyledDropdown(dojo.byId("sPhoneType"),function(){
        if(_this.phoneTypeDrop.getSelectedIndex() == 0){
            Phone.pnField.regEx = Validation.regExps.phone;
            dojo.attr(dojo.byId(Phone.pnField.id),"maxlength", 10);
        }else{
            Phone.pnField.regEx = Validation.regExps.phoneInternational;    
            dojo.attr(dojo.byId(Phone.pnField.id),"maxlength", 15);
        }
},true,64);

I fixed it. 我修好了它。 IE can be a pain. IE可能会很痛苦。 I check with the help of a colleague and IE7 excepts a different syntax than other browsers for maxlegnth. 我在同事和IE7的帮助下进行了检查,但语法与maxlegnth的其他浏览器不同。 It uses maxLegnth a capital "L". 它使用maxLegnth大写的“ L”。 So the code looks like this now: 所以代码现在看起来像这样:

this.phoneTypeDrop = new widget.StyledDropdown(dojo.byId("sPhoneType"),function(){
    if(_this.phoneTypeDrop.getSelectedIndex() == 0){
        Phone.pnField.regEx = Validation.regExps.phone;
        dojo.attr(dojo.byId(Phone.pnField.id),"maxLength", 10);
    }else{
        Phone.pnField.regEx = Validation.regExps.phoneInternational;    
        dojo.attr(dojo.byId(Phone.pnField.id),"maxLength", 15);
    }
},true,64);

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

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