我有复选框,我需要得到的按钮,复选框的值提交的控制器功能:需要在HTML中获取复选框值的值角JS到控制器
<input id="Check" type="checkbox" ng-model="CheckValue" />
我有复选框,我需要得到的按钮,复选框的值提交的控制器功能:需要在HTML中获取复选框值的值角JS到控制器
<input id="Check" type="checkbox" ng-model="CheckValue" />
$scope.CheckValue
将拥有价值你的控制器。
请在提交console.log($scope.CheckValue)
,你会在console
看到价值。
在控制器,你应该使用
$scope.CheckValue
有时它是很好的定义,你在模板中使用同样的控制器属性。因此,您将对您的变量有更清晰的概述和控制。
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" />
Thanks.this是帮了我很多。 – Coder
@Ervikas。如果它解决了您的问题,您可以接受答案。 – Zee