return {
restrict: 'EA',
link: function (scope, element, attr) {
element.bind('mouseenter', function() {
this.after("<p style='position: absolute;'><img src=" + this.src + " /></p>")
});
}
}
例如像上邊這樣,使用jquery的after方法,這個(gè)p在頁面顯示成了字串,怎麼才能直接解析出來?
利用 $compile
寫了個(gè)線上小demo
http://embed.plnkr.co/egEOkZv...
題主的引號(hào)問題所導(dǎo)致的
this.after("<p style='position: absolute;'><img src=" + this.src + " /></p>")
很明顯這裡的url少了個(gè)引號(hào)呢、img的src要用引號(hào)包裹、可以加單引號(hào)在兩邊
this.after("<p style='position: absolute;'><img src='" + this.src + "' /></p>")
你在頁面上的字串也是src沒引號(hào)