密码字段从密码中删除'/'字符

时间:2017-02-17 13:28:37

标签: javascript html angularjs

假设我的用户密码为 te / st 。 这个标记:

<input type="password" class="form-control" placeholder="Password" ng-model="password" required>
<button class="btn btn-lg btn-primary btn-block" type="submit" ng-click="login(username, password)">Sign in</button>

不知何故,ng-model中包含的值变为 test 为什么会这样?

控制器中的方法:

        $scope.login = function (username, password) {
                console.log("pass:", password);
                authService.login(username, password).then(function () {

                    console.log("auth success. username: ", username);
                },
                 function () {
                     notifications.showError("Login failed!");

                 });
            };

2 个答案:

答案 0 :(得分:1)

这个plunkr显示它确实有效 - 斜杠字符显示: https://plnkr.co/edit/tSVFtmSILTR606AZrdH1?p=preview

以下是整个测试代码:

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<input type="password" class="form-control" placeholder="Password" ng-model="password" required id="pwd">
<button onclick="alert(document.getElementById('pwd').value)">click</button>
</body>
</html>

如果您在框中键入te / st并单击按钮,您将看到:

plnkr password

答案 1 :(得分:1)

我无法复制它。如果必须,请使用以下代码。

var app = angular.module('app', []);

app.controller('ctrl', function($scope) {
  $scope.login = function(username, password){
    $scope.passedUserName = username;
    $scope.passedPassword = password;
  };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.css" />

<body ng-app="app" ng-controller="ctrl">
  <br/>
  <div class="col-lg-12">
    <div class="form-group row">
      <label for="example-text-input" class="col-2 col-form-label">User Name</label>
      <div class="col-10">
        <input type="text" class="form-control" placeholder="Username" ng-model="username" required>
      </div>
    </div>
    <div class="form-group row">
      <label for="example-text-input" class="col-2 col-form-label">Password</label>
      <div class="col-10">
        <input type="password" class="form-control" placeholder="Password" ng-model="password" required>
      </div>
    </div>
    <div class="form-group row">
      <label for="example-text-input" class="col-2 col-form-label">Value</label>
      <div class="col-10">
        <input type="text" class="form-control" placeholder="Entered Password" ng-model="password" required>
      </div>
    </div>

    <button class="btn btn-lg btn-primary btn-block" type="submit" ng-click="login(username, password)">Sign in</button>
  </div>
  <div>
  <p>Passed Username: {{passedUserName}}</p>
  <p>Passed Password: {{passedPassword}}</p>
  </div>
</body>