Re: [問題] setAttribute一串參數

看板Ajax作者 (you stay there)時間12年前 (2011/09/22 19:29), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串3/3 (看更多)
※ 引述《robinnpca (rob)》之銘言: : 我的程式如下 : var Boxs; : var ppAry = new Array(); //宣告變數ppAry是陣列// : Boxs=Rect.getAttribute("Box"); : /要取Box裡面的參數共有四組用空格分開例如 Box="0 0 100 100"/ : ppAry=Boxs.split(" ");//用空格分開// : 但是問題來了 : 1.取到的數字變成了字串 不能進行運算 : 我目前是用 : ppAry0=parseInt(ppAry[0]); : ppAry1=parseInt(ppAry[1]); : ppAry2=parseInt(ppAry[2]); : ppAry3=parseInt(ppAry[3]); : //轉成整數數字// : 問:有沒有較簡便的方式使他取出來的不是字串 : 可以直接是數字 不用這樣一個個轉換 ppAry = Boxs.split(" ").map(function(value){ return parseInt(value, 10); }); : 2.想要將運算後的Box參數放回去在 : function () : { : Rect.setAttribute("Box", "ppAry"); : //都會失敗>__<// : } Rect.setAttribute("Box", ppAry.join(' ')); : //我用alert都只顯出ppAry這五個字母>___<// : 問:要怎樣將這裡面的四個參數一次放進去呢? : 請問大家~感謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.134.117.191

09/22 21:01, , 1F
完全成功!很感謝拉!
09/22 21:01, 1F
文章代碼(AID): #1EUnmNkr (Ajax)
文章代碼(AID): #1EUnmNkr (Ajax)