Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 需要将html中复选框值的值获取给angular js中的控制器_Javascript_Jquery_Html_Angularjs - Fatal编程技术网

Javascript 需要将html中复选框值的值获取给angular js中的控制器

Javascript 需要将html中复选框值的值获取给angular js中的控制器,javascript,jquery,html,angularjs,Javascript,Jquery,Html,Angularjs,我有复选框,我需要在控制器功能中的按钮提交上获取该复选框的值: <input id="Check" type="checkbox" ng-model="CheckValue" /> $scope.CheckValue将在控制器中具有该值 提交时执行console.log($scope.CheckValue),您将在应使用的控制器中的console中看到该值 $scope.CheckValue 有时,定义在模板中使用的属性以及在控制器中使用的属性是很好的。因此,您将对变量有更清晰

我有复选框,我需要在控制器功能中的按钮提交上获取该复选框的值:

 <input id="Check" type="checkbox" ng-model="CheckValue" />

$scope.CheckValue
将在控制器中具有该值


提交时执行
console.log($scope.CheckValue)
,您将在应使用的控制器中的
console
中看到该值

$scope.CheckValue
有时,定义在模板中使用的属性以及在控制器中使用的属性是很好的。因此,您将对变量有更清晰的概述和控制。

函数forceNumber(元素){
function forceNumber(element) {
  element
    .data("oldValue", '')
    .bind("paste", function(e) {
      var validNumber = /^[-]?\d+(\.\d{1,2})?$/;
      element.data('oldValue', element.val())
      setTimeout(function() {
        if (!validNumber.test(element.val()))
          element.val(element.data('oldValue'));
      }, 0);
    });
  element
    .keypress(function(event) {
      var text = $(this).val();
      if ((event.which != 46 || text.indexOf('.') != -1) && //if the keypress is not a . or there is already a decimal point
        ((event.which < 48 || event.which > 57) && //and you try to enter something that isn't a number
          (event.which != 45 || (element[0].selectionStart != 0 || text.indexOf('-') != -1)) && //and the keypress is not a -, or the cursor is not at the beginning, or there is already a -
          (event.which != 0 && event.which != 8))) { //and the keypress is not a backspace or arrow key (in FF)
        event.preventDefault(); //cancel the keypress
      }

      if ((text.indexOf('.') != -1) && (text.substring(text.indexOf('.')).length > 2) && //if there is a decimal point, and there are more than two digits after the decimal point
        ((element[0].selectionStart - element[0].selectionEnd) == 0) && //and no part of the input is selected
        (element[0].selectionStart >= element.val().length - 2) && //and the cursor is to the right of the decimal point
        (event.which != 45 || (element[0].selectionStart != 0 || text.indexOf('-') != -1)) && //and the keypress is not a -, or the cursor is not at the beginning, or there is already a -
        (event.which != 0 && event.which != 8)) { //and the keypress is not a backspace or arrow key (in FF)
        event.preventDefault(); //cancel the keypress
      }
    });
}

forceNumber($("#myInput"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="myInput" />
要素 .数据(“旧值”,“旧值”) .bind(“粘贴”,函数(e){ var validNumber=/^[-]?\d+(\.\d{1,2})?$/; element.data('oldValue',element.val()) setTimeout(函数(){ 如果(!validNumber.test(element.val())) element.val(element.data('oldValue'); }, 0); }); 要素 .按键(功能(事件){ var text=$(this.val(); 如果((event.which!=46 | | text.indexOf('.')!=-1)&&&//如果按键不是。或已经有小数点 ((event.which<48 | | event.which>57)&&&&//然后尝试输入非数字的内容 (event.which!=45 | |(元素[0]。selectionStart!=0 | | text.indexOf('-')!=-1))&&&&//并且按键不是a-,或者光标不在开头,或者已经有一个- (event.which!=0&&event.which!=8)){//并且按键不是退格键或箭头键(在FF中) event.preventDefault();//取消按键 } if((text.indexOf('.')!=-1)和(text.substring(text.indexOf('.')).length>2)和&&//如果有小数点,且小数点后有两位数以上 ((元素[0].selectionStart-element[0].selectionEnd)==0)&&//并且未选择输入的任何部分 (元素[0]。selectionStart>=element.val().length-2)&&&//并且光标位于小数点的右侧 (event.which!=45 | |(元素[0]。selectionStart!=0 | | text.indexOf('-')!=-1))&&&&//并且按键不是a-,或者光标不在开头,或者已经有一个- (event.which!=0&&event.which!=8)){//并且按键不是退格键或箭头键(在FF中) event.preventDefault();//取消按键 } }); } forceNumber($(“#我的输入”);
谢谢。这对我帮助很大。@Ervikas。如果答案解决了你的问题,你可以接受。