2016-02-28 62 views
-2

我正在考慮修改現有的網站使用聚合物/ jquery的方式,我可以保持現有的結構,因爲它是,只是添加一些邏輯使用JQuery或聚合物到一組元素說,所有的錨標記將有點擊功能顯示彈出式窗體,可以修改該特定標籤的現有外觀和內容。聚合物或jQuery附加自定義行爲?

所以主要關心的是我應該去jquery(操縱Dom並使用一些第三方庫,如watch.js和bottle.js來獲得雙向綁定和依賴注入)還是應該繼續創建一個一套web組件,然後在我的網站中替換它們。

是否有可能使用聚合物添加自定義行爲到現有標籤,如果可以做到,那麼我可以使用它,因爲我有綁定依賴注入inbuilt在聚合物1.0。

我的意思是這與角度指令類似,我們可以將一個作用域和一組方法附加到該元素以及一些樣式和html代碼。

<div my-custom-behavior ></div> 
//above sample will attach suppose a popover to my div with a form which can be submitted to change the values in that div element 

可以在Polymer 1.0或jQuery中做類似的事情嗎?

+0

能否請你解釋得更清楚你的問題。 JS節點是什麼意思? –

回答

0

使用appendChild() method.try這

var parent=document.createElementNS("http://www.w3.org/1999/xhtml","p"); 
 
var img=document.createElementNS("http://www.w3.org/1999/xhtml","img"); 
 
img.setAttribute('src', 'https://www.planwallpaper.com/static/images/Winter-Tiger-Wild-Cat-Images.jpg'); 
 
parent.appendChild(img); 
 
document.body.appendChild(parent);