Html 内容为,
<div ng-controller="logCtrl">
<ul>
<li ng-click="logMe" someAttr="hello ricky">hello martin</li>
</ul>
</div>
Javascript 内容为,
var app = angular.module('app', []);
app.controller('logCtrl', function ($scope, $element) {
$scope.logMe = function(){
console.log("html content is " + /*---- how can i print $element's inner html text here --- */)
console.log("attribute value is " + /*---- how can i read the li element's someAttr value here --- */)
}
})
这必须在控制台中打印此消息(当用户单击鼠标时),
html content is hello martin
attribute value is hello ricky
最佳答案
尝试这样
HTML
<li ng-click="logMe($event)" someAttr="hello ricky">hello martin</li>
Controller
$scope.logMe = function(e){
var value=e.target.attributes.someAttr.value;
}
关于javascript - 访问 Controller 函数内的元素内部 html 和属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30951330/