[問題] [attribute=^value]無效有無替代的函數

看板Ajax作者 (rob)時間12年前 (2011/11/05 10:44), 編輯推噓0(0010)
留言10則, 2人參與, 最新討論串1/1
PS:最新測試出來 竟然在firefox可以 但是卻在opera中失效?.. 但是opera對svg的支援較多..這!有解嘛? 還是只能期待jquey或opera的修正(我不知道這問題事出在哪一邊>_<) $("g[id^='trans']") 想選取開頭為trans的id卻都失效? 但是直接選單一id或g標籤都可以成功 想請問 像getElementById這種指令有沒有辦法像jquey一樣 可以一起抓某些開頭的id 因為想一起改變其中的一個屬性 但是都無法成功... 我下列詳細的html檔(這裡面用jquery svg plugin的load功能需要將此html當放在 apache等伺服器(如xampp)下才能運作也就是標題需為127.0.0.1下;如果直接執行檔案會出現load 錯誤..先提醒一下有意測試的大大,避免浪費您的時間) <html> <head> <script type="text/javascript" src="" rel="nofollow">http://code.jquery.com/jquery.js"></script> <script type="text/javascript" src="" rel="nofollow">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)"); //上面這個會失敗?不知道為什麼?這指令沒有問題在其他網頁測試過 //感覺應該是load的方式不知道跑到記憶體哪裡去?jquey的此語法無法成功? //$("g").attr("transform","translate(20,5)");//這個就會成功? alert("after="+svg.toSVG());//但是卻無法取代attr? }); }); </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> 需要load的red.svg (用筆記本存,需另存成utf-8格式在改附檔名為.svg放在上面html同目錄) <svg version="1.1" xmlns="" rel="nofollow">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> -- 寧願天空是藍色~ 也不願心情是藍的! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.233.4.14 ※ 編輯: robinnpca 來自: 118.233.4.14 (11/05 11:40) ※ 編輯: robinnpca 來自: 118.233.4.14 (11/05 12:01)

11/06 16:26, , 1F
我測試的結果,應該是opera+svg在query上的bug
11/06 16:26, 1F

11/06 16:27, , 2F
11.60應該會ok
11/06 16:27, 2F

11/06 16:27, , 3F
document.querySelectorAll('g[id^=trans]')有東西
11/06 16:27, 3F

11/06 16:34, , 4F
主要症狀是說opera下svg+包含屬性的查詢(就是有[]的)
11/06 16:34, 4F

11/06 16:34, , 5F
好像會查不到東西... 不過到11.60應該會ok才對
11/06 16:34, 5F

11/06 18:46, , 6F
太厲害了!這也能測到..不知如何跟opera反應?這樣才不
11/06 18:46, 6F

11/06 18:46, , 7F
會枯等..
11/06 18:46, 7F

11/06 18:47, , 8F
忘了問.意思就是opera不是jquery相容性的問題歐!
11/06 18:47, 8F

11/06 19:04, , 9F
就11.60應該會改善囉~
11/06 19:04, 9F

11/06 19:14, , 10F
thanks!
11/06 19:14, 10F
文章代碼(AID): #1EjACX-r (Ajax)