[AJAX] 微妙的時間差
(引用 https://blog.ericsk.org/archives/800)
Nice IE!Nice Firefox!
Nice IE
最近在寫一些會用到 AJAX 的網頁,目前使用的 JavaScript framework 是 jQuery,於是乎,會有類似這樣(方便舉例而寫)的 code:
<a href="#" onclick="$('#content').load('/url/for/XXX');">Load XXX</a> <div id="content"></div>
<p>
而 <code>/url/for/XXX</code> 這個頁面有引入一個 <code>XXX.js</code> 檔案,為了在 <code>/usr/for/XXX</code> 全部讀進 <code>div#content</code> 後作一些 event handling 的 initialization,所以我在 <code>XXX.js</code> 裡有這麼一段:
</p>
<p class="hl-surround">
<p class="hl-main">
<pre><span class="hl-reserved">function </span><span class="hl-identifier">XXX_init</span><span class="hl-brackets">(</span><span class="hl-identifier">e</span><span class="hl-brackets">) {
// 作一些 initializations.. }
使用Js來讓IE支援png圖片透明效果
var arVersion = navigator.appVersion.split("MSIE") var version = parseFloat(arVersion[1])
function fixPNG(myImage) { if ((version >= 5.5) && (version < 7) && (document.body.filters)) { var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "" var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "" var imgTitle = (myImage.title) ? "title='" + myImage.title + "' " : "title='" + myImage.alt + "' " var imgStyle = "display:inline-block;" + myImage.style.cssText var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + myImage.width + "px; height:" + myImage.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>" myImage.outerHTML = strNewHTML } }
使用方法 :
javascript正則表達式中用於replace
正則表達式我經常用,但是用的都是最基礎的,基本上都是用於驗證一個字符串的合理性。例如:
var m=”12345″;
var n=/^\d+$/;
if(n.test(m)) alert(‘ok’);
PHP MySQL Tips
Continuing from my earlier post on PHP performance, I thought I’d share a few Mysql tips that I’ve learnt over the years. Hope it helps someone and please leave a comment with your own tips or provide any corrections to the ones mentioned.
Word searching
SELECT * FROM TABLE WHERE MATCH (`field`) AGAINST ('Keyword')
(Fastest)
IE中打開UTF-8編碼title為中文的網頁會顯示空白頁的問題
(忘了引用來源)
很久很久以前(大概2005年10月 ~2006年3月),當時在blogger.com寫Blog。當時blogger.com有中文界面,對中文用戶也算是比較關心了,不過 blogger.com的所有模版裡都有一個問題,那就是
注音 漢語拼音 preg_split 正規劃切割
$Hupinyin = array(
‘ㄅ’=>’b’,’ㄆ’=>’p’,’ㄇ’=>’m’,’ㄈ’=>’f’
,’ㄉ’=>’d’,’ㄊ’=>’t’,’ㄋ’=>’n’,’ㄌ’=>’l’
,’ㄍ’=>’g’,’ㄎ’=>’k’,’ㄏ’=>’h’
,’ㄐ’=>’j’,’ㄑ’=>’q’,’ㄒ’=>’x’
,’ㄓ’=>’zh’,’ㄔ’=>’ch’,’ㄕ’=>’sh’,’ㄖ’=>’r’
,’ㄗ’=>’z’,’ㄘ’=>’c’,’ㄙ’=>’s’
,’ㄚ’=>’a’,’ㄛ’=>’o’,’ㄜ’=>’e’,’ㄝ’=>’e’
,’ㄞ’=>’ai’,’ㄟ’=>’ei’,’ㄠ’=>’ao’,’ㄡ’=>’ou’
,’ㄢ’=>’an’,’ㄣ’=>’en’,’ㄤ’=>’ang’,’ㄥ’=>’eng’
,’ㄦ’=>’er’
,’ㄧ’=>’i’,’ㄨ’=>’u’,’ㄩ’=>’u’
);
$word = “ㄢ”;
foreach ($Hupinyin as $k => $v) {
if ($k == $word){
echo “$word = $v
\n”;
}
}
月曆
STYLE TYPE=”text/css”>
a{text-decoration:none}
<!–
BODY {
font-size: 12px;
color:gray;
text-decoration: none;
font-family: Arial, Verdana, Helvetica, sans-serif;
SCROLLBAR-FACE-COLOR: #fcfcd8;
SCROLLBAR-HIGHLIGHT-COLOR: #fcfcd8;
SCROLLBAR-SHADOW-COLOR: #fcd8b4;
SCROLLBAR-3DLIGHT-COLOR: #fcd890;
SCROLLBAR-ARROW-COLOR: #fcd800;
SCROLLBAR-TRACK-COLOR: #fcfcd8;
SCROLLBAR-DARKSHADOW-COLOR: #fcd8b4;
SCROLLBAR-BASE-COLOR: #fcfcd8}
A:link { font-size: 12px; color=#66ccff;}
A:alink { font-size: 12px; color=#66ccff;}
A:visited { font-size: 12px; color=#333333;}
A:hover{ font-size: 12px; color=#fcd800; text-decoration: underline overline}
TABLE {
font-size: 12px
}
亂數取碼當成驗證碼的問題
//此副程式的功能在於生成驗證碼圖片
//重設亂數種子
srand((double)microtime()*1000000);
//產生一組6位數的數字
$abc=substr(md5(uniqid(rand())),mt_rand(0,15),6);
//建立一個 80*30 畫素的圖形
$img = imagecreate(80,30);
//設定顏色
$white = imagecolorallocate($img,255,255,255);//設定背景顏色為白色
$gray = ImageColorAllocate($img,150,150,150);//設定顏色為灰色