我在DIV上加載了不同的SVG,它工作正常,但onclick綁定不起作用。在加載後將'onclick'事件附加到SVG元素'rect'
加載後,我調用LoadSVGBindings函數來設置onclick綁定。
它工作的唯一方法是通過調試FireFox。 在LoadSVGBindings函數停止後,恢復一切正常。
//HTML code
<div id="TheSVG"></div>
//LoadSVG function
function LoadSVG(Mode){
$.ajax({
type: "GET",
url: 'data/' + Mode + '.svg',
dataType: "text",
contentType: "charset=UTF-8",
success: function(data) { $('#TheSVG').html(data); },
error: function(request, status, error) {alert("Error: " + error);},
});
SetSVGBindings();
}
//Set after loading the SVG
function SetSVGBindings(){
$('polygon').on('click', function() {
alert("polygon");
});
$('rect').on('click', function() {
alert("rect");
});
}
我找不出什麼問題或如何使它正常工作。
我簡直不敢相信! – TresRRR
它就像一個魅力。 – TresRRR