angular.js - 指令里生成的html怎么解析
問(wèn)題描述
return { restrict: ’EA’, link: function (scope, element, attr) {element.bind(’mouseenter’, function() { this.after('<p style=’position: absolute;’><img src='http://www.4tl426be.cn/wenda/ + this.src + ' /></p>')}); }}
比如像上邊這樣,使用jquery的after方法,這個(gè)p在頁(yè)面顯示成了字符串,怎么才能直接解析出來(lái)?
問(wèn)題解答
回答1:利用 $compile
寫了個(gè)在線小demo
http://embed.plnkr.co/egEOkZv...
回答2:題主的引號(hào)問(wèn)題導(dǎo)致的
this.after('<p style=’position: absolute;’><img src='http://www.4tl426be.cn/wenda/ + this.src + ' /></p>')
很明顯這里的url少了個(gè)引號(hào)呢、img的src要用引號(hào)包裹、可以加單引號(hào)在兩邊
this.after('<p style=’position: absolute;’><img src=’' + this.src + '’ /></p>')
你在頁(yè)面上的字符串也是src沒(méi)引號(hào)
相關(guān)文章:
1. docker images顯示的鏡像過(guò)多,狗眼被亮瞎了,怎么辦?2. android - 百度地圖加載完成監(jiān)聽3. 關(guān)于docker下的nginx壓力測(cè)試4. nignx - docker內(nèi)nginx 80端口被占用5. java - 阿里的開發(fā)手冊(cè)中為什么禁用map來(lái)作為查詢的接受類?6. macos - mac下docker如何設(shè)置代理7. python3.x - git bash如何運(yùn)行.bat文件?8. dockerfile - [docker build image失敗- npm install]9. golang - 用IDE看docker源碼時(shí)的小問(wèn)題10. docker api 開發(fā)的端口怎么獲取?
