Html 如何将输入文本框值发送到 angularjs onclick 文本框?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21751718/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:55:49  来源:igfitidea点击:

How to send the input text box value to angularjs onclick on the text box?

htmlangularjs

提问by maho

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:

我的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 angular js function. I tried the below code but not working please suggest me

我在警报框中成功获取了输入值,但是如何在另一个 angular js 函数中获取此值。我尝试了下面的代码但不起作用请建议我

<input type =text id = "id" value = {{c.id}} ng-model = user.id ng-click ="init(user)" > </input> 

采纳答案by kubuntu

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)" />

回答by Rick

A much more cleaner way to accomplish the same thing would be to just set the value on the click event for example.

例如,完成同样事情的更简洁的方法是只设置点击事件的值。

<td onclick="user.id=ID"> </td>