2010年6月28日

JQuery 初探

JQuery:javascript library
主要在處理DOM文件操作.
主要功能:快速選取元素並對元素做處理
有許多plugin

選取範例:

$("div").addClass("classname");

$("div");

$("#body");

$("div#body");

$("div.classname p");

$("div > div");

$("div:has(div)");

對選取元素做處理:

$("a[target]").append("(some words)");
<a href="" target="_top"> some words </a>

$("#body").css({
border: xxx;
heifht: xxx;
});
修改css屬性.

$("form").submit(function(){
if ($("input#username").val()=="")
$("span.help").show;
});
表單送出前判斷username欄位,是否為空值,如為空值則出現help區的文字.

$("a#open").click(function(){
$("#menu").show();
return false;
});
點選id為open的連結,顯示id為menu的區域,傳回false,避免真的換頁.

$("#menu").slideDown("fast");
將id為menu的區塊以下拉式快速顯示.

$("div").animate({
width:'300',
padding: '20px'
},'slow');
將所有div漸漸變為 width 300 , padding 20

$("div").hide(500,function(){
$(this).show(500);
});
所有div以0.5秒動態隱藏,再以0.5秒動態顯示

$("#body").load("sample.html div > h1");
將sample.html裡的div下的h1的內容加入目前文件id為body的元素內.

$.getJSON("test.json",function(data){
for(var idx in data)
$("#menu").append("<li>+data[idx]+"</li>);
});
test.json檔案內容
[
"hello","world!"
]
透過getJSON()取得JSON格式資料

$("div").hide().css("color","blue").slideDown();
連續使用函數

find()
根據之前找到的元素再找裡面的元素

end()
回上一層所選擇的元素

$(document).ready(function(){
alert('Welcome!!');
});
較windows.onload優先執行.
且不需等文件內所有元件(如圖片)下載完就可執行.
也可
$(function(){
alert('Welcome!!');
});

防止 $() 與其他library相衝
jQuery.noConflice();
jQuery(document).ready(function(){
jQuery("div").addClass("classname");
});
或是另設別名
var $j = jQuery.noConflict();
$j(document).ready(function(){

$j("div").addClass("classname");
});

2010年6月19日

ADSL固定IP自動重撥

So-Net撥接固定IP有時侯會撥到別的IP,此Script是判斷如果IP不是原本那個,就再重撥.

#!/bin/bash


checkip=`/sbin/ifconfig ppp0 grep 'inet addr' sed 's/^.*addr://g' | sed 's/ P-t-P.*$//g'`

if [ "$checkip" != "你的固定IP" ];
then
/usr/sbin/pppoe-stop
/usr/sbin/pppoe-start
sleep 10

if !(cat /proc/net/dev | grep ppp0) > /dev/null 2>&1
then
/usr/sbin/pppoe-stop
/usr/sbin/pppoe-start
fi
fi

2010年6月17日

PHP錯誤訊息 Allowed memory size of xxx bytes exhausted

執行PHP出現以下錯誤訊息
Allowed memory size of xxx bytes exhausted ......

修改php.ini
找到memory_limit = 8M 改為 32M

2010年6月16日

Debian+IceWM桌面環境+pcmanfm 安裝筆記

安裝X Server.
apt-get install xserver-xorg
apt-get install xinit(for /usr/bin/startx)

/etc/X11/xorg.conf(調整解析度設定)
=================================================
Section "Screen"
        Identifier      "Default Screen"
        Device          "Generic Video Card"
        Monitor         "Generic Monitor"
        DefaultDepth    24
        SubSection "Display"
                Depth           1
                Modes           "800x600" "640x480"
        EndSubSection
        SubSection "Display"
                Depth           4
                Modes           "800x600" "640x480"
        EndSubSection
        SubSection "Display"
                Depth           8
                Modes           "800x600" "640x480"
        EndSubSection
        SubSection "Display"
                Depth           15
                Modes           "800x600" "640x480"
        EndSubSection
        SubSection "Display"
                Depth           16
                Modes           "800x600" "640x480"
        EndSubSection
        SubSection "Display"
                Depth           24
                Modes           "800x600" "640x480"
        EndSubSection
EndSection
=================================================

安裝視窗管理員.
apt-get install icewm

mkdir ~/.icewm
copy keys,menu,preferences,theme,toolbar to here

安裝中文字型
apt-get inatll ttf-arphic-ukai ttf-arphic-uming

安裝kdm
apt-get install kdm
修改為root可以登入kdm
/etc/kde3/kdm/kdmrc
AllowRootLogin=true

安裝pcmanfm
apt-get install pcmanfm

vi .gtkrc-2.0
gtk-icon-theme-name="gartoon"

使用pcmanfm顯示桌面圖示
編輯->遍好設定->桌面  (V)管理桌面並顯示檔案圖示

安裝mlterm
apt-get install mlterm

RedHat的YUM

yum search 套件名稱
yum install 套件名稱

XP自動登入

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

[DefaultUsername]
[DefaultPassword] 如沒有則新增字串值DefaultPassword

AutoAdminLogon設為1,如沒有則新增字串值AutoAdminLogon

2010年6月14日

apache2載入要使用的模組

不知為何apache2在/etc/apache2/httpd.conf 這個檔案變成空的.

好像把所有功能都模組化寫到/etc/apache2/mods-available裡面

如果要加入模組功能要在 /etc/apache2/mods-enabled 建立link
比方說要加入userdir這個模組好了:

ln -s ../mods-available/userdir.conf userdir.conf
ln -s ../mods-available/userdir.load userdir.load

之後再重新啟動apache即可.


新指令
a2enmod userdir

就會自動把 uerdir 模組的連結加到 /etc/apache2/mods-enabled/ 目錄下