文章详情页
angular.js - 指令里生成的html怎么解析
浏览:234日期: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里类似的语法是什么呢?
相关文章:
1. docker-compose中volumes的问题2. boot2docker无法启动3. docker容器呢SSH为什么连不通呢?4. dockerfile - 为什么docker容器启动不了?5. docker安装后出现Cannot connect to the Docker daemon.6. nignx - docker内nginx 80端口被占用7. node.js - antdesign怎么集合react-redux对input控件进行初始化赋值8. java - SSH框架中写分页时service层中不能注入分页类9. 关docker hub上有些镜像的tag被标记““This image has vulnerabilities””10. 关于docker下的nginx压力测试
排行榜

网公网安备