因此,我使用jqPlot,它有這個愚蠢的要求,它需要一個元素的id
屬性來繪圖。獲取一個元素的ID沒有?
但是,我的JavaScript使用jQuery,它對元素進行操作,而且我不想依賴具有id的div。
我可以在某種程度上給定一個jQuery $(this)
元素,爲div生成一個id
,並將該ID傳遞給我的jqPlot函數?
事情是這樣的:
(function($){ //jquery plugin style
$.fn.myPlot = function(){
//Somehow get id for "this"
var generatedId = somehowCreateID(this);
jqPlot.plot(generatedId);
}
})(jQuery);
任何提示讚賞!