gpt4 book ai didi

javascript - 如何更新 ng-model 值

转载 作者:行者123 更新时间:2023-11-28 08:45:40 24 4
gpt4 key购买 nike

    <form class="well form-search">
<input type="text" id="reference" ng-model="reference" name="reference" class="input-large search-query">
<button ng-click="getDetail(reference)" class="btn">Search</button>
</form>

我有一个函数可以更新引用输入并为其提供焦点,但是按钮上的 ng-click 函数无法触发

Angular 新手

function reffocus(ovalue) {
$("#reference").val(ovalue);
$("#reference").focus();
}

最佳答案

这样的东西会起作用(和 here is a plunker ):

*注意:如果您已经安装了 ng-appng-controller,则无需在此处进行设置。

<form class="well form-search" ng-app="myApp" ng-controller="Ctrl">
<input type="text" id="reference" ng-model="reference" name="reference" class="input-large search-query">
<button ng-click="getDetail()" class="btn">Search</button>
</form>

Javascript:

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

myApp.controller('Ctrl', function($scope) {

$scope.getDetail = function() {

// $scope.reference will be initialized by ng-model
console.log($scope.reference);
}
});

关于javascript - 如何更新 ng-model 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19839512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com