[英]How to get the value of the div in jquery?
I am using JQUERY in my angularjs project since in some special conditions(AMP). 我在angularjs项目中使用JQUERY,因为在某些特殊条件下(AMP)。
<div data-ng-repeat = "comment in blog.comments">
<i class="icon-edit font20 edit-faq-icon pointer" id="edit-comment" data-ng-click="editComment(comment);"></i>
</div>
Previously I had ng-click and now I can only find event by jquery. 以前我有ng-click,现在我只能通过jquery找到事件。
$('#edit-comment').click(function(){
alert('hi');
})
But I want to access the parameter passed( comment
) in the function editComment(comment)
. 但我想访问传递的参数(
comment
的功能) editComment(comment)
。
Write a scope function in your angular controller like the below function. 在角度控制器中写一个示波器功能,如下面的功能。 You will get the comment as parameter.
您将获得评论作为参数。
$scope.editComment=function(comment)
{
$scope.comment=comment;
};
Set an html content like this. 设置这样的html内容。
<div ng-model="comment" id="Comment"></div>
Now you can use $('#Comment').val() to get the value in click 现在你可以使用$('#Comment')。val()来获取click中的值
you can use .text() method to get the value of div. 你可以使用.text()方法来获取div的值。 also you can refer the following link http://api.jquery.com/text/
您也可以参考以下链接http://api.jquery.com/text/
You can get the comment by passing the comment as a parameter to ng-click function. 您可以通过将注释作为参数传递给ng-click函数来获取注释。
var app = angular.module("myApp", []); app.controller("myCntrlr",function($scope){ $scope.blog= { name:"Naresh", comments:["test comment 1","test comment 2","test comment 3"] } $scope.editComment = function(comm){ alert(comm); }; });
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.js'></script> <div ng-app="myApp" ng-controller="myCntrlr"> <div ng-repeat = "comment in blog.comments"> <button ng-click="editComment(comment);">get Comment</button> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.