【问题标题】:How to change placeholder for single textbox in angular?如何以角度更改单个文本框的占位符?
【发布时间】:2014-12-30 12:46:57
【问题描述】:

嗨,朋友们,我有单选按钮 “%”“计数”

如果我点击“%”,那么在文本框中“%”应该是占位符

如果我点击“计数”,那么“计数”应该是同一个文本框的占位符

这里小提琴链接:http://jsfiddle.net/qbauuzj2/

HTML

       <div class="winner-par">
        <p>Winner Parameter</p>
        <div class="onoffswitch-green2">
          <input type="radio" id="radios5" name="radiosg5" class="SwitchOn" value="true" checked 
         ng-click="radioChecked()">
          <label for="radios5">%</label>
          <input type="radio" id="radios6" name="radiosg5" class="SwitchOff" value="false" ng-click="radiounChecked()">
          <label for="radios6">Count</label>
        </div>
      </div>
      <input type="text">

【问题讨论】:

    标签: angularjs


    【解决方案1】:

    您可以动态更新 DOM 元素

    <div ng-app="" ng-controller="Controller">
        ...
        <input type="text" placeholder="{{placeholder}}" />
    </div>
    

    你的控制器

    function Controller($scope) {
    
        $scope.radioChecked = function ()
        {
            $scope.placeholder="%";
            $scope.apply();
        }
    
        $scope.radiounChecked = function ()
        {
            $scope.placeholder="Count";
            $scope.apply();
        }
    }
    

    http://jsfiddle.net/z21qfwqz/14/

    如果您使用 >1.1.3 角度版本 - 对于这个 ng-attr-placeholder 更好的方法(感谢 Teq1

    <input type="text" ng-attr-placeholder="{{placeholder}}" />
    

    Look at this

    【讨论】:

    【解决方案2】:

    按照这个例子:

    Change value of input placeholder via model?

    根据所选择的,更改范围内“占位符”变量的值,然后将该变量绑定到元素上的占位符属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-28
      • 2020-05-20
      • 2019-02-25
      相关资源
      最近更新 更多