聯動下拉菜單

<div id="div1"></div>
    window.onload = function () {
        var s1 = new Sel('div1');
        s1.add('0',['中國','美國','日本'])
        s1.add('0_0',['深圳','廣州','北京'])
                 s1.add('0_0_0',['寶安','南山','福田'])
                 s1.add('0_0_1',['天河','越秀','海珠'])
                 s1.add('0_0_2',['西城','東誠','崇文'])
        s1.add('0_1',['波士顿','芝加哥','休斯敦'])
                s1.add('0_1_0',['子波士1','子波士2','子波士3'])
                s1.add('0_1_1',['子芝加1','子芝加2','子芝加3'])
                s1.add('0_1_2',['子休斯1','子休斯2','子休斯3'])
        s1.add('0_2',['東京','横滨','大阪'])
                s1.add('0_2_0',['子東京1','子東京2','子東京3'])
                s1.add('0_2_1',['子横滨1','子横滨2','子横滨3'])
                s1.add('0_2_2',['子大阪1','子大阪2','子大阪3'])
        s1.init(3);

    }
//寫構造函數
    function Sel(id) {
        this.oParent = document.getElementById(id);  //ID變成對象的屬性;
        this.data = {} //寫對象存函數 key = value
        this.aSel = this.oParent.getElementsByTagName('select'); //創建全局屬性,獲取所有select才能找到 獲得第一個select aSel[0]
    }
//寫原型
    Sel.prototype = {
//初始化
        init: function (num) {
            var This = this; //原型對像
            for (i = 1; i <= num; i++) {
                var oSel = document.createElement('select');
                var oPt = document.createElement('option');
                oPt.innerHTML = '默認';
                oSel.appendChild(oPt);
                oSel.index = i;
                this.oParent.appendChild(oSel)
                oSel.onchange = function () {
                    This.change(this.index) //this改變指向  this是下拉菜單,This對象
                }
            }
            this.first();
        },
        add: function (key, value) {
            this.data[key] = value;
        },
        first: function () {
            var arr = this.data['0'];//得到key 比如 s1.add('0',['中國','美國','日本'])  this.date['0'];得到['中國','美國','日本']
            for (var i = 0; i < arr.length; i++) {
                var oPt = document.createElement('option');
                oPt.innerHTML = arr[i] // ['中國','美國','日本']
                this.aSel[0].appendChild(oPt)
            }
        },
        //開始做第一個onchange下拉事件。
        change: function (iNow) { //iNow 當前下拉菜單的索引 0 1 2 3 
            var str = '0';
            for(var i = 0;i<iNow;i++){
                str += '_'+ (this.aSel[i].selectedIndex - 1);
                //s1.add('0',['中國','美國','日本']) 因為前面還有個默認,select裏一共有四個值,選擇1的索引值是1 但所對應的應該是 s1.add('0_0',['深圳','廣州','北京'])中的0_0,要開成這個形式必須 - 1
            }
            if( this.data[str] ){ //0_0 0_1 0_2
                var arr = this.data[str] //對應第二項數組['深圳','廣州','北京'] ['波士顿','芝加哥','休斯敦']['東京','横滨','大阪']
                this.aSel[iNow].options.length = 1; //只保留‘默認’這一項option
                for( var i = 0;i<arr.length;i++){
                    var oPt = document.createElement('option');
                    oPt.innerHTML = arr[i];
                    this.aSel[iNow].appendChild(oPt);
                }
                this.aSel[iNow].options[1].selected = true //選第一項時第二項自動變直接選中
                iNow++;  //遞歸,連動三個
                if(iNow < this.aSel.length){
                    this.change(iNow)
                }
            }
            else{//選擇默認時走else
                if(iNow < this.aSel.length)//小於下位菜單的長度;
                this.aSel[iNow].options.length = 1; //選擇默認時變回來
            }
        }
    }

運行

CENTOS VPS 配置 | wordpress環境安裝

一、查看當前硬盤情況

fdisk -l

二、新建分區

fdisk /dev/xvdb

SSH執行以上命令,會提示下方填寫區域(請見有色字)

Command (m for help): n 新建分區 
Command action
 e extended
 p primary partition (1-4) 
p 分區類型 
Partition number (1-4): 1 分區編號
 First cylinder (1-1305, default 1):1
Using default value 1 分區起始位置,默認即可 
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): 1305
結束位置,默認即可 
Command (m for help): t 指定分區格式 
Selected partition 1
Hex code (type L to list codes): 83 設置為Linux分區 
Changed system type of partition 1 to 8e (Linux LVM) 
Command (m for help): w 保存 
The partition table has been altered! 
Calling ioctl() to re-read partition table. Syncing disks.

三、再次執行fdisk命令查看當前分區狀態

fdisk -l
partprobe #若沒有問題則執行此命令寫入內核

四、將分區格式化為ext3

mkfs.ext3 /dev/xvdb1

五、掛載到/home

mount /dev/xvdb1 /home
df -l

六、寫入掛載文件

echo "/dev/xvdb1 /home ext3 defaults 1 3" >> /etc/fstab

SSH執行以上命令,寫入/etc/fstab,開機時自動掛載。
//多IP綁定
編輯文件

/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0:0
onboot=YES
BOOTPROTO=static
IPADDR=1.2.3.4
NETMASK=255.255.255.0
GATEWAY=1.2.3.1
vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
/etc/init.d/networking restart

//配置php環境
1、更新系統內核到最新【可不做】

yum -y update

2、CentOS默認以安裝了apache2.2如果沒有則

yum -y install httpd

apache擴展

yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

3、Web中文亂碼:

/etc/httpd/conf/httpd.conf

AddDefaultCharset UTF-8 改 AddDefaultCharset Off
添加以下文件:

AddCharset us-ascii.ascii .us-ascii
AddCharset ISO-8859-1  .iso8859-1  .latin1
AddCharset ISO-8859-2  .iso8859-2  .latin2 .cen
AddCharset ISO-8859-3  .iso8859-3  .latin3
AddCharset ISO-8859-4  .iso8859-4  .latin4
AddCharset ISO-8859-5  .iso8859-5  .cyr .iso-ru
AddCharset ISO-8859-6  .iso8859-6  .arb .arabic
AddCharset ISO-8859-7  .iso8859-7  .grk .greek
AddCharset ISO-8859-8  .iso8859-8  .heb .hebrew
AddCharset ISO-8859-9  .iso8859-9  .latin5 .trk
AddCharset ISO-8859-10  .iso8859-10  .latin6
AddCharset ISO-8859-13  .iso8859-13
AddCharset ISO-8859-14  .iso8859-14  .latin8
AddCharset ISO-8859-15  .iso8859-15  .latin9
AddCharset ISO-8859-16  .iso8859-16  .latin10
AddCharset ISO-2022-JP .iso2022-jp .jis
AddCharset ISO-2022-KR .iso2022-kr .kis
AddCharset ISO-2022-CN .iso2022-cn .cis
AddCharset Big5.Big5   .big5 .b5
AddCharset cn-Big5 .cn-big5
# For russian, more than one charset is used (depends on client, mostly):
AddCharset WINDOWS-1251 .cp-1251   .win-1251
AddCharset CP866   .cp866
AddCharset KOI8  .koi8
AddCharset KOI8-E  .koi8-e
AddCharset KOI8-r  .koi8-r .koi8-ru
AddCharset KOI8-U  .koi8-u
AddCharset KOI8-ru .koi8-uk .ua
AddCharset ISO-10646-UCS-2 .ucs2
AddCharset ISO-10646-UCS-4 .ucs4
AddCharset UTF-7   .utf7
AddCharset UTF-8   .utf8
AddCharset UTF-16  .utf16
AddCharset UTF-16BE .utf16be
AddCharset UTF-16LE .utf16le
AddCharset UTF-32  .utf32
AddCharset UTF-32BE .utf32be
AddCharset UTF-32LE .utf32le
AddCharset euc-cn  .euc-cn
AddCharset euc-gb  .euc-gb
AddCharset euc-jp  .euc-jp
AddCharset euc-kr  .euc-kr
#Not sure how euc-tw got in - IANA doesn't list it???
AddCharset EUC-TW  .euc-tw
AddCharset gb2312  .gb2312 .gb
AddCharset iso-10646-ucs-2 .ucs-2 .iso-10646-ucs-2
AddCharset iso-10646-ucs-4 .ucs-4 .iso-10646-ucs-4
AddCharset shift_jis   .shift_jis .sjis

4、虛擬主機,配置文件

vi /etc/hosts

加上www.xxx.com的域名解析
5、配置虛擬站點

vi /etc/httpd/conf.d/vhost.conf
NameVirtualHost x.x.x.x:80
<VirtualHost x.x.x.x:80>
   DocumentRoot /home/wwwroot
   ServerName xxx.com
   ServerAlias  *.xxx.com
   <Directory "/home/wwwroot">
       #  AllowOverride AuthConfig
       #  Options Indexes
       AllowOverride all
       Order Deny,Allow
       Deny from all
       Allow from all
       ErrorDocument    404 /404.php
   </Directory>
   DirectoryIndex index.php
</VirtualHost>

註:多IP情況,NameVirtualHost x.x.x.x:80 不能省略 & 同IP只須定義1次,否則warn…
6、安裝PHP
停止Apache2 的服務

/etc/init.d/httpd stop
yum -y install httpd php
yum -y install php-gd php-xml php-mbstring php-ldap php-pear
/etc/init.d/httpd restart

7、MYSQL安裝

yum -y install mysql mysql-server php-mysql
yum -y install mysql-connector-odbc mysql-devel libdbi-dbd-mysql

8、啟動服務

/sbin/chkconfig httpd on        [設置apache為自啟動]
/sbin/chkconfig mysqld on       [設置mysqld服務為自啟動]
/sbin/service httpd start       [啟動 httpd 服務]
/sbin/service mysqld start      [啟動mysqld服務]

9、root用戶密碼

mysqladmin -u root password '新密碼'    [設置mysql.root密碼]

讓mysql數據庫更安全
登錄

mysql -u root -p [此時會要求妳輸入剛剛設置的密碼,輸入後回車即可]

mysql -u root -p

mysql -rroot -p密碼
mysql> DROP DATABASE test; [刪除test數據庫]
mysql> DELETE FROM mysql.user WHERE user = “”; [刪除匿名帳戶]
mysql> FLUSH PRIVILEGES; [重載權限]

新建數據庫:

mysql > create database 數據庫名;

新建對應用戶:

my sql > grant all on 數據庫名.* to 用戶名@localhost identified by ‘密碼';

刷新

flush privileges;
quit退出;

安裝wordpress

wget http://cn.wordpress.org/wordpress-3.8.1-zh_CN.tar.gz /home/目錄/

解壓

tar -zxvf wordpress-3.8.1-zh_CN.tar.gz

移動

mv ./wordpress/* /home/目錄/

升級PHP以使用phpmyadmin3.0以上版本
添加源文件 xxx.repo [任意命名,擴展為repo即可]

vi /etc/yum.repos.d/abc.repo

復制

[phpupdate]
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

:wq
yum update php

Y.Y
此時可能亂碼.
安裝phpmyadmin

wget http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/3.4.2/phpMyAdmin-3.4.2-all-languages.tar.gz

移到/usr/share

mv phpMyAdmin-3.4.2-all-languages.tar.gz /usr/share

解壓

cd /usr/share
tar xvf phpMyAdmin-3.4.2-all-languages.tar.gz

改名

cd phpMyAdmin-3.4.2-all-languages
mv config.sample.inc.php config.inc.php

編輯config.inc.php

vi config.inc.php

以下內容去掉//

// $cfg['Servers'][$i]['controluser'] = 'pma';?
// $cfg['Servers'][$i]['controlpass'] = 'pmapass';
// $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
// $cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';
// $cfg['Servers'][$i]['relation'] = 'pma_relation';
// $cfg['Servers'][$i]['table_info'] = 'pma_table_info';
// $cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';
// $cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';
// $cfg['Servers'][$i]['column_info'] = 'pma_column_info';?
// $cfg['Servers'][$i]['history'] = 'pma_history';
// $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';
$cfg['Servers'][$i]['controluser'] = 'pma'; [把'pma'修改為妳的帳號]
$cfg['Servers'][$i]['controlpass'] = 'pmapass'; [把'pmapass設置為妳的mysql登錄密碼]
$cfg['blowfish_secret'] = ”;  [添加短語密碼例如:$cfg['blowfish_secret'] = 'onohot';] 

[如不設提示:配置文件現在需要1個短語密碼的解決方法]
軟鏈接

sudo ln -s /usr/share/phpMyAdmin-3.4.2-all-languages /home/目錄/phpmyadmin

即可使用目錄下所綁定域名訪問:http://www.xxx.com/phpmyadmin

reboot

配置ssl
安裝mod_ssi

yum install mod_ssl

位置 /etc/httpd/conf.d/ssl.conf 查看以下位置

SSLCertificateFile/etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile/etc/pki/tls/private/localhost.key

進入/etc/pki/tls/private 刪除 rm-f localhost.key
opensslgenrsa 1024 > localhost.key
返回/certs
maketestcert 自動

opensslreq -new -x509 -days 365 -key ../private/localhost.key -outlocalhost.crt 手動
localhost.crt —-ssl.conf指定命名

再次打開/etc/httpd/conf.d/ssl.conf

DocumentRoot “/home/wwwroot”
ServerName xxx.com

重啟apache
至此可用https訪問,IE6少提示警告。
結束
錯誤:缺少 mcrypt 擴展

wget http://www.atomicorp.com/installers/atomic
sh ./atomic
yum  install  php-mcrypt  libmcrypt  libmcrypt-devel
reboot

錯誤:phpMyAdmin 高級功能未全部設置,部分功能不可用

script/create_tables.sql

直接phpmyadmin導入即可sql,重新登入即可。
錯誤:Starting httpd: httpd: apr_sockaddr_info_get() failed for t9235
httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName

/etc/httpd/conf/httpd.conf
#ServerName www.example.com:80
改為
ServerName localhost:80

錯誤:403

<Directory />
  Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from allow
</Directory>

遞歸更改權限

chmod 777 * -R

快刪目錄

rm -rf [目錄]