• ionic 获取input的值


    1、参数传递法

    例子:获取input框内容

    这里有个独特的地方,直接在input处使用 #定义参数的name值,注意在ts中参数的类型

    在html页面中
      

    <ion-input type="text" placeholder="请输入账号" #username></ion-input>
      <ion-input type="password" placeholder="请输入密码" #password></ion-input>
      <button (click)="login(username, password)">登录</button>

    在ts文件中

     

     login(username: HTMLInputElement, password: HTMLInputElement) {
        console.log(username.value)
        console.log(password.value)
      }

    2、双向绑定法

    这种方法比较通用,但是需要在ts中定义对应的变量

    例子1:获取input框内容

    在html页面中

     

     <ion-input type="text" placeholder="请输入账号" [(ngModel)]="username"></ion-input>
      <ion-input type="password" placeholder="请输入密码" [(ngModel)]="password"></ion-input>
      <button (click)="login()">登录</button>

    在ts文件中

      

    username: string;
      password: string;
      login() {
        console.log(this.username);
        console.log(this.password);
      }

    例子2:获取单选按钮的值

    在html页面中
     

     <ion-toggle [(ngModel)]="rememberName"></ion-toggle>

    在ts文件中
      

    rememberName: any;
      login() {
        console.log(this.rememberName);
      }
  • 相关阅读:
    matlab2016b和c# .net4.0混合编程
    有限元入门
    math.net 拟合
    excel 错误提示以及其他基础知识
    excel的小bug
    Servlet体系及方法
    Servlet学习笔记
    HTTP协议
    Tomcat
    反射
  • 原文地址:https://www.cnblogs.com/yc-c/p/9580000.html
Copyright © 2020-2023  润新知