使用angularjs获取div的文本 [英] get the text of div using angularjs
本文介绍了使用angularjs获取div的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用angularjs获取div的文本.我有此代码
i want to get the text of div using angularjs . I have this code
<div ng-click="update()" id="myform.value">Here </div>
作为我的控制器的地方是这样
where as my controller is something like this
var myapp= angular.module("myapp",[]);
myapp.controller("HelloController",function($scope,$http){
$scope.myform ={};
function update()
{
// If i have a textbox i can get its value from below alert
alert($scope.myform.value);
}
});
任何人还可以要求我给angularjs提供任何好的链接吗?我没有找到angularjs参考作为学习资源.
Can anyone also recommand me any good link for angularjs . I dont find angularjs reference as a learning source .
推荐答案
您应该在函数中发送click事件,您的html代码应该是:
You should send the click event in the function, your html code should be :
<div ng-click="update($event)" id="myform.value">Here </div>
并且您的update函数应该具有event参数,您将从中获取div元素,然后从该元素中获取文本,如下所示:
And your update function should have the event parameter which you'll get the div element from and then get the text from the element like this :
function update(event)
{
alert(event.target.innerHTML);
}
这篇关于使用angularjs获取div的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文