jQuery 偵測瀏覽器版本, 作業系統(OS detection)

update: 簡易版的偵測 iphone/ipod time: 23:32 jQuery 真是一個相當方便的 javascript framework,最近在弄嵌入式系統時候需要去偵測瀏覽器 user agent,就類似下此訊息 “Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)",原本打算直接用 C 語言內建的 getenv(“HTTP_USER_AGENT”) 來做掉,不過後來想想,直接在 UI 那邊,利用 jQuery 來偵測瀏覽器版本、系統OS,這樣就解決了,上網找到有人寫了 jQuery browser and OS detection plugin,利用底下語法就可以知道一些 user agent 裡面的資料


    

[Read More]

[CodeIgniter] 利用 jQuery 簡易驗證使用者帳號/Email

codeigniter_2
好久沒寫相關

CodeIgniter 文章,針對於剛入門 CI 的新手們,此篇教學如何使用 jQuery AJAX 搭配 CI 來驗證使用者帳號及相關資訊,本篇教學帶您如何在 CI 中發出 AJAX request 給伺服器端。 請先在網頁 header 自行 include jQuery 檔案,或者可以使用 Google AJAX CDN 方式來讀取,將底下程式碼放到之前:

$(document).ready(function() {
    /* 先停止讀取狀態 */
    $('#Loading').hide();

    /* 填寫好 email 欄位,按下 Tab 會進行讀取 */
    $('#email').blur(function(){
    /* 讀取 email 欄位 */
	var a = $("#email").val();
    /* email 正規語法 */
	var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
    /* 簡易驗證 email */
	if(filter.test(a)){
        /* 讀取狀態 */
		$('#Loading').show();
        /* AJAX 比對資料庫 */
		$.post("controller_name/check_email_availablity", {
			email: $('#email').val()
		}, function(response){
            /* 驗證後讀取 reponse 狀態 */
			$('#Loading').hide();
			setTimeout("finishAjax('Loading', '"+escape(response)+"')", 400);
		});
		return false;
	}
});
[Read More]

Html5 模板架構(Boilerplate)

HTML5 Boilerplate - A rock-solid default for HTML5 awesome._1282574693481 今年在 COSCUP 大會上最主流的議題就是 Html5,今天看到一個網站 HTML5 Boilerplate,這網站提一個全新 html 5 模板,自從離開 Dreamweaver 樣板軟體,利用 Pspad 手動撰寫 html,此網站就發揮非常大的用處,提供全新 html,CSS 以及 javascript,支援了底下很多功能:

  • 跨瀏覽器 (IE6…)
  • 支援多種 html5 Tag
  • Compress 和 cache html 檔案
  • CSS IE6 , IE7 Hack
  • IE6 Png Fix (連這個都幫忙解決了)
  • 支援 CDN jQuery,避免在 local 端沒讀取到檔案 你還可以根據自己需要的功能做添加或者是減少,CSS reset、跨瀏覽器 CSS、robots.txt、Apache .htaccess cache 壓縮也有支援,如果不需要的功能,也可以參考看看,對於初學者也是非常好的學習例子。

[網站] 好站連結 (七) Android, javascript, Css, PHP, Perl, FreeBSD, Linux

Windows C# C# 比較字串 MSDN 比較字串 Request.Form Collection Request Query String / Form Parametrs ASP.NET QueryString Usage Using include files with ASP.NET html [將所有 的內容包到一個 中][7] apache Fixing mod_rewrite and .htaccess on GoDaddy Hosting javascript jQuery Week Calendar Javascript: reference the parent window from a popup How to get and set form element values with jQuery How to check and uncheck a checkbox with jQuery Loop through parameters passed to a Javascript function perl-completion. [Read More]

[jQuery] 解決 IE6 PNG 透明背景 (Supersleight jQuery Plugin for Transparent PNGs in IE6)

今天無意間看到 Drew McLellan 在 2007 年寫了這篇 Transparent PNGs in Internet Explorer 6,真的是太晚發現這篇了,之前自己寫到一篇:『[CSS] IE 6, 7, 8 FireFox hack 支援透明背景圖 background or img javascript』,雖然 Google 官方網站宣佈完全不支援 IE6 瀏覽器,打算只支援 Microsoft Internet Explorer 7.0+, Mozilla Firefox 3.0+, Google Chrome 4.0+, Safari 3.0+,可是我們這些 Web Developer 還是需要考慮客戶的瀏覽器阿,因為客戶才是最大的,尤其是在一些學術機構,安裝好 XP,預設就是 IE6,從 Google 分析裡面,IE6 也是網站的客戶大群。 先來介紹 Drew McLellan 寫的一支好用 js 來改善所有 png 透明圖檔,最主要是修正 background-image 跟 img tag 所包含的 png 圖檔 先下載:Download SuperSleight,解壓縮放到 js 資料夾 針對 IE6 瀏覽器寫入 html [Read More]

[jQuery] AjaxFileUpload : Multiple File Upload plugin

最近 survey 一些 AJAX upload plugin by jQuery,或者是一些網路知名 upload opensource: SWFUpload, 以及目前很強大的 Plupload,先來說明 AjaxFileUpload 這個 jQuery Plugin 單一檔案上傳,如果想要簡單方便的單一上傳,我很推薦這個,搭配回傳的 json type 吐出錯誤訊息還蠻好用的,雖然作者給單一上傳的說明,不過還是可以將它改成多檔上傳,也就是多增加 input type=“file” 就可以了,底下介紹一下怎麼實作單一檔案或者是多檔案上傳。 單一檔案上傳 先 include AjaxFileUpload javascript html: jQuery code: function ajaxFileUpload() { //這部份可以省略,或者是撰寫當 ajax 開始啟動需讀取圖片,完成之後移除圖片 $("#loading") .ajaxStart(function(){ $(this).show(); }) .ajaxComplete(function(){ $(this).hide(); }); /* prepareing ajax file upload url: the url of script file handling the uploaded files fileElementId: the file type of input element id and it will be the index of $_FILES Array() dataType: it support json, xml secureuri:use secure protocol success: call back function when the ajax complete error: callback function when the ajax failed */ $. [Read More]

遲來的 jQuery 1.4 Released

為了慶祝 jQuery 四週年慶,官方網站終於 Release 1.4 版本了,也大幅度修改了 jQuery API 網站,跟以往一樣,jQuery 提供兩種版本讓大家測試跟下載:jQuery Minified (23kb Gzipped),這版本是利用 Google Closure Compiler 去壓縮,以往好像是用 YUI Compressor,另一版本就是沒經過壓縮:jQuery Regular (154kb),當然 Google 也提供了 host 來讓 jQuery 有 cache 檔案作用,增加網站速度: http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js 1.4 版本的出來,最主要就是效能的改善,以及整個 Code Base 翻修,可以參考 John Resig 寫的 JavaScript Function Call Profiling,看到底下的圖,就大致上知道 1.4 的效能改善 4271690739_f0bced3a78 (by appleboy46) .css() and .attr() 效能改善圖: 4271691147_fd72853fa4 (by appleboy46) 整篇都在說明 jQuery 效能的部份,真的是改善很多,Media Temple 主機商也贊助 jQuery 14天的徵文活動,大家可以上去看看有很多影片都是在介紹 jQuery,最後得獎的人可以獲得 13" MacBook Pro,真是太吸引人了。 最後可以參考 黑暗執行緒大大寫的:jQuery 1.4 小閱兵

[jQuery] ThickBox 3.1 無限期停止支援維護

Oceanic / 人生海海 看到這篇 thickbox 停止維護ThickBox jQuery plugin 裡面算是不錯用的工具,在網路上常常會聽到這個名詞,thickbox 作者也推薦了底下類似套件:

fancybox 的,目前開發專案都以它為主,因為在瀏覽整頁圖片,我覺得效果不錯,剛剛去 try 了一下 colorbox,發覺這套也不錯用。在 fancybox 裡面設定 zoomSpeedIn 或者是 frameWidth 的值,就直接設定數字,不用在加上引號,不然會沒出現效果。

$(document).ready(function() {
	$("a.group").fancybox({
		'zoomSpeedIn': 300, 
		'zoomSpeedOut': 300
	});
});

[jQuery] 驗證表單實作筆記 API/1.3/Selectors

驗證 form 表單屬於前端的工作,非常重要,避免使用者填錯格式,當然在 jQuery Plugin 可以找到專門驗證表單的外掛:jQuery plugin: Validation,此外掛不能相容於 IE 6,會沒辦法呈現效果,google 到一篇解決方法:Validating not happening in IE6 & no error removal on keyup,這篇裡面提到,必須使用 un-packed and un-minified 的版本,也就是沒有壓縮過的 javascript 檔案,不過我自己沒有試過就是了,底下針對表單的 checkbox select input radio 欄位做檢查的筆記,可以讓大家參考看看。 在 jQuery 1.3 裡面正式拿掉 [@attr] 的寫法,所以以前寫 $(“input:radio[@name=reg_sex]”) 都要改成 $(“input:radio[name=reg_sex]”),這樣才是正確的,可以參考 jQuery Selector 這篇的 Attribute Filters 部份,先來一篇網路上實做提示說明在 text 來未:jQuery: show plain text in a password field and then make it a regular password field on focus 作法很簡單:建立兩個輸入 password 的 text input 欄位:

[Read More]