文章详情页
angular.js - 指令里生成的html怎么解析
浏览:293日期: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>')}); }}
比如像上边这样,使用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没引号

标签:
HTML
上一条:angular.js - Angular2配合webpack的使用方式下一条:angular.js - angular里的ui-view里,获取当前页面的状态参数用$state.params,在vue里类似的语法是什么呢?
相关文章:
排行榜

网公网安备