Below is my html:
下面是我的html:
<tr ng-repeat="c in client">
<td><input type =text id = "id" value = {{c.id}} onclick = "display();" > </input> </td>
<td><input type =text value = {{c.fname}}></td>
</tr>
My js:
function display()
{
var x=document.forms["form"]["id"].value;
alert(x);
}
I am getting the input value in the alert box successfully but how to get this value in another angulr js function. I tried the below code bt not working please suggest me
我成功地在警报框中获取输入值,但是如何在另一个angulr js函数中获取此值。我尝试了下面的代码bt不工作请建议我
<input type =text id = "id" value = {{c.id}} ng-model = user.id ng-click ="init(user)" > </input>
2 个解决方案
#1
3
If you have set up your application properly, you simply create the init()
function in your controller
如果已正确设置应用程序,只需在控制器中创建init()函数即可
$scope.init = function (user) {
// function implementation
};
Also make sure you format your HTML correctly
还要确保正确格式化HTML
<input type="text" id="id" value="{{c.id}}" ng-model="user" ng-click ="init(user)" />
#2
-1
A much more cleaner way to accomplish the same thing would be to just set the value on the click event for example.
一个更简洁的方法来完成同样的事情就是在click事件上设置值,例如。
<td onclick="user.id=ID"> </td>
#1
3
If you have set up your application properly, you simply create the init()
function in your controller
如果已正确设置应用程序,只需在控制器中创建init()函数即可
$scope.init = function (user) {
// function implementation
};
Also make sure you format your HTML correctly
还要确保正确格式化HTML
<input type="text" id="id" value="{{c.id}}" ng-model="user" ng-click ="init(user)" />
#2
-1
A much more cleaner way to accomplish the same thing would be to just set the value on the click event for example.
一个更简洁的方法来完成同样的事情就是在click事件上设置值,例如。
<td onclick="user.id=ID"> </td>