Javascript SVG对象部分上的JQuery click()不一致
我试图实现一个隐藏SVG某些层的函数。 它在某种程度上起作用,但对用户点击的反应是不一致的。有时调用show hide函数,有时什么也不发生。如果我双击svg中的文本将被选中。。。如何实现更好的单击事件处理程序Javascript SVG对象部分上的JQuery click()不一致,javascript,jquery,svg,Javascript,Jquery,Svg,我试图实现一个隐藏SVG某些层的函数。 它在某种程度上起作用,但对用户点击的反应是不一致的。有时调用show hide函数,有时什么也不发生。如果我双击svg中的文本将被选中。。。如何实现更好的单击事件处理程序 <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> Switch - demo</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.4.4.min.js'></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.js"></script>
<script type='text/javascript' src="http://keith-wood.name/js/jquery.svg.js"></script>
<script type='text/javascript' src="http://keith-wood.name/js/jquery.svganim.js"></script>
<style type='text/css'>
#svgbasics { width: 600px; height: 500px; border: 1px solid #484; }
</style>
<script type='text/javascript'>//<![CDATA[
function drawOpenSwitch(svg){
//Boolean states for switches:
var f1closed = false;
var q1closed = false;
var changeSwitch = function (){
$('#closed3Pswitch').hide();
$('#closed3Prelay').hide();
$('#f1Button').click(function() {
if(f1closed == false){
$('#open3Pswitch').hide();
$('#closed3Pswitch').show();
}else{
$('#closed3Pswitch').hide();
$('#open3Pswitch').show();
}
f1closed=!f1closed;
});
$('#q1Button').click(function() {
if(q1closed == false){
$('#open3Prelay').hide();
$('#closed3Prelay').show();
}else{
$('#closed3Prelay').hide();
$('#open3Prelay').show();
}
q1closed=!q1closed;
});
};
svg.clear();
var switchElement=svg.load('./fullschema_connected_combined.svg', {onLoad: changeSwitch, addTo: true, changeSize: true});
}
$(window).load(function(){
$(function() {
$('#svgbasics').svg({onLoad: drawOpenSwitch});
});
});//]]>
</script>
</head>
<body>
<div id="svgbasics"></div>
</body>
</html>
交换机-演示
#svgbasics{宽度:600px;高度:500px;边框:1px实心#484;}
//
原来问题在于我使用的是带箭头的线条(Inkscape)。。。其中的线是按钮的一部分,但箭头不是。因此,只有当鼠标指针刚好位于箭头下方细线上方时,它才起作用。替换名为q1Button和f1Button的图形组解决了此问题