attribute^=value 无法通过 jQuery SVG 插件加载 svg
最新: 我发现问题是歌剧!它可以在firefox中运行!但是我需要opera才能使用它,有什么解决办法吗? PS:等待jquery或opera的即将推出的版本吗?
我想问为什么$("g[id^=trans]")不能工作,而$("g")可以?如何解决? jQuery SVG插件的load方法必须在Apache等服务器下才能工作。(我不知道为什么?但如果不在Apache下就无法工作) JavaScript
<html><head><script type="text/javascript" src="http://code.jquery.com/jquery.js">
</script><script type="text/javascript" src="http://keith-wood.name/js/jquery.svg.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#svgload").svg();
var svg = $('#svgload').svg('get');
$('#loadsvg').click(function() {
svg.load('red.svg',{onLoad:loadDone});
});function loadDone(svg, error) {
svg.text(10, 20, error || 'Loaded into ' + this.id);
}
$('#transform').click(function(){
//alert($("g").attr("transform"));
alert("before="+svg.toSVG());
$("g[id^=trans]").attr("transform","translate(20,5)");//this cannot work!How to fix it?
//$("g").attr("transform","translate(20,5)");//this can work!
alert("after="+svg.toSVG());
});
});</script></head><body>
<div id="svgload" width="200px" height="200px" >
</div>
<button id="loadsvg" type="button">loadsvg</button>
<button id="transform" type="button">transform</button></body></html>`
SVG:
<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
<g id="trans001">
<rect x="35" y="50" width="20" height="20" fill="#F3D70A" stroke-width="4"/>
<line x1="20" y1="40" x2="80" y2="40" stroke-width="5"/>
<circle cx="20" cy="60" r="10" fill="red" stroke="blue" stroke-width="5"/></g>
<g id="trans002"><rect width="35" height="20" x="20" y="90" fill="blue">
</rect></g>
</svg>
The newest:
I find the question is the opera! It can work in the firefox!But I need opera to use it,does it have any solution? PS:waiting the jquery or opera's uncoming version?
I want to ask why $("g[id^=trans]") cannot work,but the $("g") can?How to fix it?
The load method of jQuery SVG plugin must work under the server such as Apache.(I don't know why?But it will not work if not under the Apache)
The javascript
<html><head><script type="text/javascript" src="http://code.jquery.com/jquery.js">
</script><script type="text/javascript" src="http://keith-wood.name/js/jquery.svg.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#svgload").svg();
var svg = $('#svgload').svg('get');
$('#loadsvg').click(function() {
svg.load('red.svg',{onLoad:loadDone});
});function loadDone(svg, error) {
svg.text(10, 20, error || 'Loaded into ' + this.id);
}
$('#transform').click(function(){
//alert($("g").attr("transform"));
alert("before="+svg.toSVG());
$("g[id^=trans]").attr("transform","translate(20,5)");//this cannot work!How to fix it?
//$("g").attr("transform","translate(20,5)");//this can work!
alert("after="+svg.toSVG());
});
});</script></head><body>
<div id="svgload" width="200px" height="200px" >
</div>
<button id="loadsvg" type="button">loadsvg</button>
<button id="transform" type="button">transform</button></body></html>`
The SVG:
<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
<g id="trans001">
<rect x="35" y="50" width="20" height="20" fill="#F3D70A" stroke-width="4"/>
<line x1="20" y1="40" x2="80" y2="40" stroke-width="5"/>
<circle cx="20" cy="60" r="10" fill="red" stroke="blue" stroke-width="5"/></g>
<g id="trans002"><rect width="35" height="20" x="20" y="90" fill="blue">
</rect></g>
</svg>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 jQuery 选择器是错误的 - 尝试:
请注意,属性值上的引号是强制性的 (http://api.jquery.com/attribute-starts-with-selector/)
Your jQuery selector is wrong - try:
Note that the quotes on the attribute value are mandatory (http://api.jquery.com/attribute-starts-with-selector/)