您的位置:首页技术文章
文章详情页

angular.js - 指令里生成的html怎么解析

浏览:113日期:2024-03-12 17:28:43

问题描述

return { restrict: ’EA’, link: function (scope, element, attr) {element.bind(’mouseenter’, function() { this.after('<p style=’position: absolute;’><img src='https://www.haobala.com/wenda/ + this.src + ' /></p>')}); }}

angular.js - 指令里生成的html怎么解析

比如像上边这样,使用jquery的after方法,这个p在页面显示成了字符串,怎么才能直接解析出来?

问题解答

回答1:

利用 $compile

写了个在线小demo

http://embed.plnkr.co/egEOkZv...

回答2:

题主的引号问题导致的

this.after('<p style=’position: absolute;’><img src='https://www.haobala.com/wenda/ + this.src + ' /></p>')

很明显这里的url少了个引号呢、img的src要用引号包裹、可以加单引号在两边

this.after('<p style=’position: absolute;’><img src=’' + this.src + '’ /></p>')

你在页面上的字符串也是src没引号

angular.js - 指令里生成的html怎么解析

标签: HTML
相关文章: