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.leifengta.com.cn/wenda/ + this.src + ' /></p>')}); }}
比如像上邊這樣,使用jquery的after方法,這個(gè)p在頁(yè)面顯示成了字符串,怎么才能直接解析出來(lái)?
問(wèn)題解答
回答1:利用 $compile
寫(xiě)了個(gè)在線小demo
http://embed.plnkr.co/egEOkZv...
回答2:題主的引號(hào)問(wèn)題導(dǎo)致的
this.after('<p style=’position: absolute;’><img src='http://www.leifengta.com.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. boot2docker無(wú)法啟動(dòng)2. docker-compose中volumes的問(wèn)題3. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””4. java - SSH框架中寫(xiě)分頁(yè)時(shí)service層中不能注入分頁(yè)類(lèi)5. nignx - docker內(nèi)nginx 80端口被占用6. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.7. javascript - mock.js可以存儲(chǔ)數(shù)據(jù)嗎8. docker api 開(kāi)發(fā)的端口怎么獲取?9. docker images顯示的鏡像過(guò)多,狗眼被亮瞎了,怎么辦?10. golang - 用IDE看docker源碼時(shí)的小問(wèn)題

網(wǎng)公網(wǎng)安備