以下是一个示例代码,演示如何在AngularJS中分配和读取两个不同提交按钮的值。
HTML代码:
按钮1的值:{{button1Value}}
按钮2的值:{{button2Value}}
AngularJS代码:
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.submitButton1 = function() {
$scope.button1Value = $scope.inputValue;
};
$scope.submitButton2 = function() {
$scope.button2Value = $scope.inputValue;
};
});
在上面的示例中,我们首先创建了一个AngularJS应用程序,并将其绑定到HTML元素上。然后,在控制器中定义了两个函数submitButton1()
和submitButton2()
,分别用于处理按钮1和按钮2的点击事件。在这些函数中,我们将输入框中的值分配给相应的作用域变量button1Value
和button2Value
。最后,我们在HTML中使用插值表达式{{}}
来显示这些变量的值。
这样,当用户在输入框中输入值后,点击按钮1或按钮2时,相应按钮的值将被分配给button1Value
或button2Value
,并显示在页面上。