2012年6月14日 星期四

setTimeout 傳物件參數

先看一下一般 setTimeout 怎麼用


function hello(){alert('Hello!');}
setTimeout("hello()", 1000);

在指定 function 時是以字串方式編寫
若要傳靜態參數則用字串相加方式

function hello(text){alert(text);}
var hellostring = "Hello! Welcome to Earth!";
setTimeout("hello(" + hellostring + ")", 1500);

但是以這種方式在碰到要傳物件時就會出錯

function hello(a, e){
     $("#pop") .html("Welcom to " + a.children('span').first().text() + "").css({
           'top':e.pageY -10,
           'left':e.pageX + 20
     }).fadeIn();
}
$(function(){
     $(".pop").mouseenter(function(e){
           setTimeout("hello(" + this + "," + e  + ")", 1000);  //丟過去不是要的物件
     });
}) ;

    <@div id="pop" style="display:none;position:absolute">

    <@a href="http://google.com" class="pop">

        <@span>google

    <@/a>

    <@a href="http://yahoo.com" class="pop">

        <@span>yahoo

   

 要改寫成

setTimeout((function (a,e){ return function (){ hello(a,e); } })(this, e), 1000);

這樣才能以物件方式傳送

--
參考網頁
http://blog.longwin.com.tw/2011/12/javascript-settimeout-args-2011/

2012年6月8日 星期五

moodle htmlarea in chrmoe & safari

解決 moodle 1.9.2 不能在 chrome 及 safari 中使用 html 編輯器的問題。

因為原本的 html 編輯器不認識新的瀏覽器

故要加上幾行讓它認得 chrome or safari 並允許它們使用

官方解決方法

可以下載第二個 patch 及可。


2012年5月9日 星期三

無效的 Viewstate

在寫 .net 時想要用 javascript 送出 post,但卻發視會有錯誤訊息「無效的 Viewstate」。
官網上的說法
Viewstate 只能發佈回相同頁面。 嘗試的 aspx 表單張貼至另一個頁面將會失敗並 Viewstate 無效的例外狀況。 這項行為是經過設計。
 意思就是不可以這樣子搞啦  XD