cor*_*114 11 ionic-framework ionic3
我试图添加ion-inputfor maxlength,max属性但它没有按预期工作.
<ion-input type="number" placeholder="*" maxlength="1"></ion-input>
<ion-input type="number" placeholder="*" max="1"></ion-input>
Run Code Online (Sandbox Code Playgroud)
有谁知道相同的解决方案?
谢谢
Dav*_*idX 15
根据这篇文章:Chrome中的输入类型="数字"忽略了maxlength
Maxlength对输入类型="数字"不起作用
这里建议一个替代方案:https://github.com/ionic-team/ionic/issues/7072 其中dilhan119建议使用type ="tel"
一个强大的解决方案是使用表单验证器,它将阻止表单提交(并可以向用户显示错误):https://www.joshmorony.com/advanced-forms-validation-in-ionic-2/
小智 5
HTML:\n <ion-textarea [(ngModel)]=\xe2\x80\x9ctext\xe2\x80\x9d (ionChange)="textareaMaxLengthValidation()"></ion-textarea>\n <ion-input type="text" [(ngModel)]=\xe2\x80\x9ctext\xe2\x80\x9d (ionChange)="textareaMaxLengthValidation()"></ion-input>\n\n\n TS:\n textareaMaxLengthValidation()\xc2\xa0{\n \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0if\xc2\xa0(text.length\xc2\xa0>\xc2\xa050)\xc2\xa0{\n \xc2\xa0\xc2\xa0\xc2\xa0text=\xc2\xa0text.slice(0,\xc2\xa050);\n \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0}\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
10273 次 |
| 最近记录: |