我想設置一個ID拉斐爾集,因爲我想一個事件點擊後顯示它。設置一個ID爲「Raphaeljs設置」
這是我的設置:
var divResult = document.getElementById('printResult');
var space2Draw = Raphael(divResult, 1600, 900);
var st = space2Draw.set();
st.push(
space2Draw.circle(newXCoordinates, newYCoordinates, 20).click((function (valore) {
return function() {
window.open("index-point.html?id=" + (valore) + "&type=" + type + "&description=" + description + "&name=" + name);
}
}(valore))).mouseover(function() {
this.attr({ 'cursor': 'pointer' });
this.attr({ 'opacity': '.50' });
}).mouseout(function() {
this.attr({ 'opacity': '1' });
})
);
在我的網頁
我有一個按鈕:
function show(){
var element = space2Draw.getById(-1);
element.show();
}
}
是不是可以設置一個ID這樣:set.id = -1? 我該如何設置一個ID然後找到該設置?
在此先感謝您的幫助。
我嘗試過:st.node.setAttribute(「id」,「element_id」),bur我有一個錯誤:Uncaught TypeError:無法調用未定義的方法'setAttribute' – ilamaiolo
我已經重寫了我的答案來解釋這一點。看起來Raphael不能將這個集合當作一個對象,所以setAttribute方法是不適用的。相反,您需要更改集合中的每個對象(併爲其分配一個CSS類)。請參閱上文以獲取更完整的解釋。 – gatotkaca