目前分類:程式語言 (17)

瀏覽方式: 標題列表 簡短摘要
因為專案需要,開發網頁輸入程式

其中有檢查同個名稱為slColumn的select 

用document.main.slColumn.length檢查
在多個slColumn下,上述方法會檢查出正確的名稱為slColumn數量

但是只有一個slColumn,document.main.slColumn.length 會等於document.main.slColumn.options.length

所以不能用slColumn.length來檢查slColumn數量

請改用DOM取得名稱為slColumn的物件

var oslColumn= document.getElementsByName("slColumn");

再用 oslColumn.length 取得slColumn數量
而 oslColumn[i] 則可取得第i個slColumn物件

接下來 oslColumn[i].length 就會是 options的數量了

bgm 發表在 痞客邦 留言(0) 人氣()

藍色小舖

http://www.blueshop.com.tw/board/show.asp?subcde=BRD20020307142601RJ7&fumcde=FUM200410061525290EW&rplcnt=15


下面說明,因為include 為SEVER SIDE SSI語法,所以前後的if、select判斷式都不會執行

http://www.learnasp.com/freebook/asp/inc.aspx

Include Files

The include option is the heart of making efficient ASP files and re-usable chunks. It basically 
has two forms and now we will present the forms and their differences:

<!--#include virtual="/whatever.asp"-->
would include any file on your site (in this example, whatever.asp is in the web server's root directory) 
but you must fully qualify the filename with a path.

<!--#include file="whatever.asp"-->
can include the whatever.asp file in  the directory of the script that contains the statement. 
It ASSUMES the current directory!

Example #1
<!--#include virtual="/sally/filename.asp"-->
could include a file from sally's directory, even if the page with this statement is (for example) 
in the /fred/finance folder.

Example #2:
<!--#include file="/sally/filename.asp"-->
will fail from fred's directory.

Example #3:
<!--#include file="../sally/filename.asp"-->
will succed from fred's directory but if the script that contains it is moved to a different level in the tree structure 
it will fail to locate the file. INCLUDE VIRTUAL is better if a script may be moved and is immune to relative path issues.

IMPORTANT: Include files are always processed and inserted before ASP scripts on the page are calculated. Thus a page with many IFs and SELECT CASEs that selectively include files in fact always include the file before the script begins executing.


請參考下面的動態載入方式

Includes Files Dynamically

The include files are gathered and processed BEFORE any ASP code. Soif your code looks like this:

<%SELECT CASE
     CASE 1 %>
    <!--#include virtual="whatever1.asp"-->
     CASE 2 %>

    <!--#include virtual="whatever2.asp"-->
     CASE 3 %>
    <!--#include virtual="whatever3.asp"-->
<%END SELECT%>

Three includes are performed before any ASP code is executed.

YOU CANNOT DO:

<%
     whichfile="1"%>
  <!--#include virtual="whatever<%=whichfil%>.asp"-->

Though this is a reasonable idea.

<!--#include virtual="whatever.asp"-->

We however have coded a workaround that is FREE you may find useful. The workaround is:

   filename=/learn/test/includedynamic.asp

<Test Script Below>

<html><head>


<TITLE>includedynamic.asp</TITLE>


</head><body bgcolor="#FFFFFF">


<%


whichfile="bookscifi.asp"


Call ReadDisplayFile(whichfile)


response.write "<hr>"





whichfile="bookhorror.asp"


Call ReadDisplayFile(whichfile)


response.write "<hr>"








whichfile="/learn/test/bookmarketing.asp"


Call ReadDisplayFile(whichfile)


response.write "<hr>"


%>





</body></html>


<%


SUB ReadDisplayFile(FileToRead)


whichfile=server.mappath(FileToRead)


Set fs = CreateObject("Scripting.FileSystemObject")


Set thisfile = fs.OpenTextFile(whichfile, 1, False)


tempSTR=thisfile.readall


response.write tempSTR


thisfile.Close


set thisfile=nothing


set fs=nothing


END SUB


%>


 

 

The only downside to this method is no ASP Code ( i.e. anything in <% %> ) will be parsed or executed in the included file. If you must execute ASP code the Win2k server.execute @
/freebook/asp/incwin2k.aspx
or the 3rd party components like ASPHTTP must be employed @
/learn/include/asphttp.asp



Includes - Other Sites/Dynamic FileNames

3rd party components like ASPHTTP can grab the HTML contents of a specific URL into an ASP string. Supports GET/POST/HEAD documents via the HTTP protocol, examining response headers, transfering requests to a file (including binary transfers) and password authentication support. They can also be used on YOUR OWN SITE to make dynamic includes possible.

available at http://www.serverobjects.com/products.htm

Microsoft includes WinInet which seems to be ideally suited for this EXCEPT is currently not thread safe, see:
http://www.learnasp.com/advice/threadsafe.asp
so Tools like ASPHTTP are a necessity.

Here is a sample where ASPHTTP is used to grab contents from another site.

   filename=/learn/test/asphttpother.asp

<Test Script Below>

<html><head>


<title>asphttpother.asp</title>


</head>


<body>


<%


Set HttpObj = Server.CreateObject("AspHTTP.Conn")





HttpObj.Url = "http://www.funinspace.com"


strResult = HttpObj.GetURL





STRresult=server.htmlencode(STRresult)


response.write STRresult





SET HTTPobj = nothing


%>


</body>


</html>








 

 

Here is a sample where ASPHTTP is used to allow a string to decide  which page on our site is executed.

   filename=/learn/test/asphttpdynamic.asp

<Test Script Below>

<html><head>


<title>asphttpdynamic.asp</title>


</head>


<body bgcolor="#FFFFFF">


<%


mystring="/learn/test/response.asp"





Set HttpObj = Server.CreateObject("AspHTTP.Conn")


HttpObj.Url = "http://www.learnasp.com" & mystring


strResult = HttpObj.GetURL


response.write STRresult





SET HTTPobj = nothing


%>


</body>


</html>



或是下面網址的方式









http://www.asp101.com/articles/michael/dynamicincludes/default.asp

Dynamic Include Files

by Michael Qualls 

Introduction


This is an advanced example and it assumes that you are already familiar with HTML, ASP,
and using ActiveX Objects. In it I use the FileSystemObject and TextStream Objects to create
"dynamic" includes.

Dynamic Include Files


I think that at one time or another all of us have attempted to create dynamic include files
in our ASP applications only to find out that it would not work. The usual approach was to
use a variable to hold the name of the file that you wanted to include and then pass the
name of that variable to the include directive.
Let us be clear: The following code will not work:
<%


'A variable is declared to hold a file name


Dim MyFile





'The desired file name is passed to the variable.


MyFile = Request("SomeFileName")





'Then the variable holding the file name is passed


'to the include directive.


%>


<!--#include file=<%=MyFile%>-->


The reason that this code listing will not work is because in Active Server Pages the include
directives are resolved before the server-side script portions are processed.
The above code listing will trigger a nasty error telling you that the include file cannot be found.

One of the reasons to use an include file is to be a container for static HTML
that does not normally change (such as a standard header or footer).
This file is then referenced using a normal include directive. However, sometimes,
different content is needed based upon user input or some other condition.
Rather than create an entirely different web page for each and every possible condition,
the idea of using "dynamic include" files was born. However, as noted in the code listing above,
the most logical way to implement this idea does not work.

In order to get around this problem, the Microsoft FileSystemObject Object can be used to load
and pass the content of the desired include file into a string variable which can be inserted into
the page that is being sent to the client. The following function, "getFileContents",
aids in this process by loading a file that is passed to the function as an input parameter and
returning its contents as a string.

<%





'Pass the name of the file to the function.


Function getFileContents(strIncludeFile)


Dim objFSO


Dim objText


Dim strPage








'Instantiate the FileSystemObject Object.


Set objFSO = Server.CreateObject("Scripting.FileSystemObject")








'Open the file and pass it to a TextStream Object (objText). The


'"MapPath" function of the Server Object is used to get the


'physical path for the file.


Set objText = objFSO.OpenTextFile(Server.MapPath(strIncludeFile))








'Read and return the contents of the file as a string.


getFileContents = objText.ReadAll





objText.Close


Set objText = Nothing


Set objFSO = Nothing


End Function


%>


Using this function "dynamic include" files can be achieved. First, the main page
(a template file containing the page layout and any static content) would be loaded and passed
to a string variable. Then, the contents of the include file would be loaded and passed to a string variable.
Finally, the variable containing the contents of the include file would be inserted into
the contents of the variable containing the main page.

Example: Dynamic Include Files

First, lets take a look at the "template" file. In this listing, there is an HTML comment,
"<!-- INCLUDE FILE HERE -->". We will replace this HTML comment with the content of the include file.

<html>


<body>


<h2>Welcome to my web page!</h2>


<table width="500" border="1">


<tr>


<td>


<!-- INCLUDE FILE HERE -->


</td>


</tr>


</table>


</body>


</html>


Now, lets look at the include files that will be used for this example. The first include file is the
default include file. The default include file is a form that allows the client to choose which of three
include files to load. Notice that the "action" attribute of the form is omitted. This is because when
the form will be submitting to itself (causing "dynamicinc3.asp" to reload).

<!-- BEGIN DEFAULT INCLUDE -->


<form method="post">


<h3>Select the name of the file you wish to load</h3>


<p>


<select id=cboFile name=cboFile>


<option value="includefile1.inc">File #1</option>


<option value="includefile2.inc">File #2</option>


<option value="includefile3.inc">File #3</option>


</select>


<input type="submit" value="Submit">


</p>


</form>


<!-- END DEFAULT INCLUDE -->


For the sake of this example, the content of the other three include files has been kept very simple.

<!-- BEGIN INCLUDE FILE #1 -->


<h2 style="color:red">FILE #1 CONTENTS</h2>


<br>


<a href="dynamicinc3.asp">Return to default page</a>


<!-- END INCLUDE FILE #1 -->


<!-- BEGIN INCLUDE FILE #2 -->


<h2 style="color:green">FILE #2 CONTENTS</h2>


<br>


<a href="dynamicinc3.asp">Return to default page</a>


<!-- END INCLUDE FILE #2 -->


<!-- BEGIN INCLUDE FILE #3 -->


<h2 style="color:blue">FILE #3 CONTENTS</h2>


<br>


<a href="dynamicinc3.asp">Return to default page</a>


<!-- END INCLUDE FILE #3 -->


Finally, consider the ASP file that makes the whole example run, "dynamicinc3.asp".

<%





'-------------------------------------------------------------


'The "getFileContents" function should be included at the top


'of the ASP file.


'-------------------------------------------------------------





'Declare variables to hold the content of the main page and


'the include file.


Dim strMain, strInclude





'Get the contents of the main page and pass them to the "strMain"


'variable.


strMain = getFileContents("maintemplate.inc")





'Test to see if the "cboFile" select box is being submitted. If so,


'load the requested include file. If not, load the default include.


If Request.form("cboFile") = "" Then


strInclude = getFileContents("includedefault.inc")


Else


strInclude = getFileContents(Request.form("cboFile"))


End If





'After the proper include file contents are loaded ("strInclude"),


'then insert it into the main page ("strMain") using the "Replace"


'function.


strMain = replace(strMain,"<!-- INCLUDE FILE HERE -->",strInclude)





'Use the "Response" Object to "Write" the completed page to the client.


Response.Write strMain





%>


This sample works, and, in effect, creates the ability to use dynamic include files because it does
not use the include directive. Instead this example uses the FileSystemObject Object.

This technique can be useful if you wish to keep your layout separated from your content.
You can create a template which contains the layout for your website and include files which
contain the content of the website. Then using ASP, you can combine the two for client viewing.
This is exactly the way that I put my website together!

Let me give you one last thing to think about. How would using techniques similar to this aid you
if you are storing your data in XML files?

Related Links


bgm 發表在 痞客邦 留言(0) 人氣()

轉自: http://blog.blueshop.com.tw/HammerChou/archive/2006/06/18/29105.aspx

如何使用
CDO 物件來寄 E-Mail

 

CDO ( Collaboration Data Objects ) 物件 對應檔案 CDOSYS.dll E-Mail 寄送使用;

可應用於 VB ASP .Net 是簡單的信件寄送方式之一

 

    Dim objCDO As Object

    Dim strCfg As String

 

    Set objCDO = CreateObject("CDO.Message")

    strCfg = "http://schemas.microsoft.com/cdo/configuration/"

 

    With objCDO

       

        .Sender = "別胡亂送@OhMyGod.com"

        .From = "誰是寄件者@NoOneKnows.com"

        .To = "要寄給誰@whois.com.tw"

 

        .Fields("urn:schemas:mailheader:X-Priority") = 1 ' Priority = PriorityUrgent 高優先順序

        .Fields("urn:schemas:mailheader:return-receipt-to") = "誰是寄件者@NoOneKnows.com" ' 要求讀取回條

         ' .Fields("urn:schemas:httpmail:importance") = 2 ' Importance = High

       ' .Fields("urn:schemas:httpmail:priority") = 1 ' Priority = PriorityUrgent

        .Fields.Update ' 更新欄位

       

        .Subject = "沒有主旨(放主題啦)"

       

        .TextBody = "ORZ" ' Text 文字格式信件內容

        ' HTML 網頁格式信件內容

        .HTMLBody = "<HTML>" & _

                                "<BODY>" & _

                                "<table border=""1"" width=""100%"">" & _

                                "<tr><td>I</td><td>am</td><td>Hammer</td><td>!</td></tr>" & _

                                "<tr><td>Who</td><td>r</td><td>u</td><td>?</td></tr>" & _

                                "</table>" & _

                                "</BODY>" & _

                                "</HTML>"

                               

        .AddAttachment "C:\AttFile.zip" ' 附加檔案

       

        .CC = "Xman@yahoo.com.tw"   ' 副本

        .BCC = "SpiderMan@hotmail.com.tw" ' 密件副本

       

        .Configuration(strCfg & "sendusing") = 2 ' Sendusing = SendUsingPort

        .Configuration(strCfg & "smtpserver") = "msa.hinet.net" ' SMTP Server

       ' .Configuration(strCfg & "smtpserverport") = 25 ' SMTP Server Port ( 預設即為 25 )

 

        ' SMTP Server 如需登錄 , 則需設定 UserName / Password

        ' .Configuration(strCfg & "sendusername") = "UserName" ' Send User Name

        ' .Configuration(strCfg & "sendpassword") = "Password" ' Send Password

       

        .Configuration.Fields.Update ' 更新 (欄位) 組態

       

       ' .DSNOptions = 4 ' 回傳信件傳送狀態

       '  cdoDSNDefault = 0 , DSN commands are issued.

       '  cdoDSNDelay = 8 , Return a DSN if delivery is delayed.

       '  cdoDSNFailure = 2 , Return a DSN if delivery fails.

       '  cdoDSNNever = 1 , No DSNs are issued.

       '  cdoDSNSuccess = 4 , Return a DSN if delivery succeeds.

       '  cdoDSNSuccessFailOrDelay = 14 ,Return a DSN if delivery succeeds, fails, or is delayed.

 

        .Send ' 傳送

       

    End With

   

    Set objCDO = Nothing

bgm 發表在 痞客邦 留言(0) 人氣()

create table #T(姓名 varchar(100), 科目 varchar(100), 成績 int)

insert into #T select '林', '軟件測試', 90
insert into #T select '林', '分佈式數據庫', 70
insert into #T select '王', '分佈式數據庫', 80

CREATE PROCEDURE Test2
AS

Declare @sql varchar(8000)
Select @sql = ''

--動態生成case when 語句
Select @sql = @sql + ', SUM(Case 科目 When ''' + 科目 + ''' Then 成績 Else 0 End) As ' + 科目
From #T Group By 科目

--按姓名分組
Select @sql = ' Select 姓名,' + Stuff(@sql, 1, 1, '') + ',sum(成績) as 總分 From #T Group By 姓名'


--打印出動態生成的SQL語句
print @sql

EXEC(@sql)

go


輸出的結果

姓名 分佈式數據庫 軟件測試 總分
80 0 80
70 90 160

bgm 發表在 痞客邦 留言(0) 人氣()

備份ODBC

odbc資訊存在registry下的

HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources


System DSN's are stored in the registry at the following key:

HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources

The simple method is to load REGEDIT.EXE and browse to that key and select
File-Export

You can automate this using regedit.exe via the following

regedit.exe /e "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"

Note: The command line above should be on 1 line.

You could also script this using VBScript if you like to automate this
process and have more control.

bgm 發表在 痞客邦 留言(0) 人氣()

在ASP程式中以SQLOLEDB連線到SQL Server2000

在建立連線時發生
Microsoft OLE DB Provider for SQL Server (0x80004005)
Login failed for user 'kingkong'. Reason: Not associated with a
trusted SQL Server connection
的錯誤

其中連線字串如下:
Provider=SQLOLEDB; Data Source=DDSQL02; Initial Catalog=testdb1; User ID="test1";Password="test1"

未設定
integrated Security=SSPI及Trusted_Connection=yes

網路上討論均是以未設定好SQL Server登入模式為解決方法,但經檢查後SQL Server2000 設定均為混合模式

現在發現將上面的連線字串DataSource改為IP就可解決

經使用者敘述是先灌好SQL Server 2000後,再變更電腦名稱及加入網域,是否因此造成透過SQLOLEDB連線時預先以windows帳號登入?

bgm 發表在 痞客邦 留言(0) 人氣()

MS SQL 可以用update from 
UPDATE titles
SET ytd_sales = t.ytd_sales + s.qty
FROM titles t, sales s
WHERE t.title_id = s.title_id
AND s.ord_date = (SELECT MAX(sales.ord_date) FROM sales)



但是ORACLE就只不支援

可以用

UPDATE table1 t_alias1
SET column1 =
(SELECT expr
FROM table2 t_alias2
WHERE t_alias1.column2 = t_alias2.column2);

但是些指令當table1中column2有table2裡沒有對應的資料,則column1會被update成null

再不然就只能用cursor
Example 13-7 Using UPDATE With a Subquery
-- Create a table with all the right IDs, but messed-up names
CREATE TABLE employee_temp AS
SELECT employee_id, UPPER(first_name) first_name,
TRANSLATE(last_name,'aeiou','12345') last_name
FROM employees;
BEGIN
-- Display the first 5 names to show they're messed up
FOR person IN (SELECT * FROM employee_temp WHERE ROWNUM < 6)
LOOP
DBMS_OUTPUT.PUT_LINE(person.first_name || ' ' || person.last_name);
END LOOP;
UPDATE employee_temp SET (first_name, last_name) =
(SELECT first_name, last_name FROM employees
WHERE employee_id = employee_temp.employee_id);
DBMS_OUTPUT.PUT_LINE('*** Updated ' || SQL%ROWCOUNT || ' rows. ***');
-- Display the first 5 names to show they've been fixed up
FOR person IN (SELECT * FROM employee_temp WHERE ROWNUM < 6)
LOOP
DBMS_OUTPUT.PUT_LINE(person.first_name || ' ' || person.last_name);
END LOOP;
END;


bgm 發表在 痞客邦 留言(0) 人氣()

當編譯VB程式時發生 Can't find project or library 錯誤
且IDE指向 Date String Len等應該不會發生錯誤的指令

請到 Project/References中取消勾選 有Miss字樣的References

bgm 發表在 痞客邦 留言(0) 人氣()

每個系統的基礎建設有一些必要項目

使用紀錄,內容最好要有使用者登入的帳號、使用權限、執行的功能項或更細微的動作、日期、時間另外針對這些紀錄在系統上要有VIEW、DELETE的功能;因為如果紀錄在DB中,不能保証DBA會給開發人員讀取資料的權限。而刪除功能則是怕使用率過高爆檔(如果是交易性的系統的話,這另外考量)

如果需要不同權限、身份登入系統測試,會因為SSO造成一些不便;可以考慮使用權限模擬的方式。但是如果交易系統的話,請不要作夢。

測試是很大的問題,在程式設計時所有測試項目請以特定條件設定在測試區才有功用;程式能直接由測試區不必修改就能放入版本管理系統直接上線才合格

 user 對於一套系統的好壞的感覺,並不是來自所有功能的表現,而會集中在某幾個常用的功能上面,針對這些功能需要最用心去作。自己要玩的部份等真的有空再玩吧。

模擬正式環境的測試環境要跟正式環境越像越好,要是有人回報有bug,先在這個環境上面照他提供的步驟來重建案發現場。你要知道在什麼情況下可以把這個問題慢動作播放一遍。一般說就是reproduce這個bug。
接著寫程式的人,才有辦法去找出問題的關鍵去解決。所以在記錄bug時,怎麼樣重建案發現場的reproduce procedure是很重要的記錄。 

你要叫美眉測試,要叫他們在測試環境上面測。要驗證bug有沒有被解掉,也是要在這個環境上測。要不然你家美眉到底是不是在唬弄你,或是這個新版本放上去會不會動,就是個大問號。
這個環境上應該就是上一次production的正式release,再加上programmer最近針對bug的修正。
也因為要管的環境如果很多很麻煩,最好所有上code的動作都是透過標準的script,從cvs中把code checkout再丟上去rebuild。
你要上code到正式環境(production),就是要把測試環境上的這一份丟上去。這樣,總不會有什麼測好的東西還上不了線的怪現象。當然啦,你的測試環境跟production要長的一模一樣,不要一邊用tomcat4.x,一邊用tomcat 5.5。想死也不是這樣玩的。
如果有測試資料要塞,那最好也把sql都事先準備好。這樣比較省事。

     

bgm 發表在 痞客邦 留言(0) 人氣()

.NET Framework 提供了一個System.Web.Mail Class來處理寄信電子郵件

但是實際上使用時會發生一些錯誤,下面是從各網站找來的解決方法


mail.To         = csweng@gmail.com;//收件者的email address(必要)
mail.From       = abc@some.com;//寄件者的email address(必要)
mail.Subject    = "TEST";//寄件標題  
MailMessage mail= new MailMessage();
mail.From = "csweng@gmail.com";//收件者的email address(必要)
mail.To = "abc@some.com";
mail.Subject = "TEST";
mail.Body = "THIS IS MAIL TEST!!";
if (nZipSize < 5*1024*1024) //5MB
{
 MailAttachment ma = new MailAttachment(zipFile); //夾帶附件
 mail.Attachments.Add(ma);
}
else
{
 mail.Body +=  "\r\n因檔案大於5MB無法以信件附件寄送";
}

SmtpMail.SmtpServer = "88.8.64.47";//指定SMTP SERVER
SmtpMail.Send(mail);
/*以下是SMTPMAIL需要認証時需要加入*/
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1)  
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "SMTP 登入帳號")  
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "密碼")   
     
另外請參考
http://www.systemwebmail.com/faq/3.8.aspx

http://blog.joycode.com/ghj/archive/2004/02/17/13197.aspx

http://www.blueshop.com.tw/board/show.asp?subcde=BRD20050328163711ZN1&fumcde=FUM20041006161839LRJ&rplcnt=13


bgm 發表在 痞客邦 留言(0) 人氣()

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>vForm表單驗證程序</title>
<style type="text/css">
<!--
div.info {
 width: 170px;
 overflow:visible;
 height:auto;
 font-size: small;
 position: absolute;
 background-color: #FFffdd;
 border: 1px solid #000;
 filter:progid:DXImageTransform.Microsoft.Shadow(color=#111111,direction=135,strength=3);
 top: 375px;
 padding: 5px;
 left: 671px;
}
div.info_title

.err{
 padding: 5px;
 height: 50px;
 width: 24em;
 position: absolute;
 background-color: #FFFFCC;
 left: 196px;
 top: 114px;
 font-size: small;
 opacity:0.5;
 border: 1px double #333333;
 filter: Shadow(Color=#000000, Direction=135);
 filter:progid:DXImageTransform.Microsoft.Shadow(color=#111111,direction=135,strength=5);

}
#form1 .text_input {
 border-top: 1px solid #333333;
 border-right: 1px solid #999999;
 border-bottom: 1px solid #ddd;
 border-left: 1px solid #000000;
}
.info_title {
 color: #FF0000;
 background: #ACB9D1;
}
#form1 {
 position: static;
 left: 581px;
 top: 463px;
 border: 1px solid #3300FF;
 padding: 5px;
 ;
}
#imok {
 display: block;
 position: absolute;
 height:315px;
 overflow:scroll;
 left: 100px;
 top: 100px;
 width: 306px;
}
.title h1 {
 background: #33CCFF;
 border-bottom: medium solid #3366FF;
}
.title p {
 font-size: medium;
 text-indent: 2em;
}
body {
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: medium;
}

code {
 font: 12px/18px "lucida Grande", verdana, lucida, Arial, helvetica, "宋體", sans-serif;
 border:1px solid #0099cc;
 padding:5px;
 margin: 5px;
 width: 80%;
 color: #000;
 background-color: #ddedfb;
 display: block;
}

-->
</style>
<script language="JavaScript" type="text/javascript">
//程序基本思路:通過擴展對象來實現,將String擴展 將默認的表單元素擴展 定義兩個自定義對象。
//String.isEmail
//String.isUrl
//表單元素.required
//表單元素.isvalid
//表單元素.validate
//

//字符串驗證擴展
//├電子郵件驗證
String.prototype.isEmail = function(){
 var tmpStr = this;
 var email = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
 return email.test(tmpStr)
}
//├http地址驗證
String.prototype.isUrl = function(){
 var url = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
 var tmpStr = this;
 return url.test(tmpStr);
}
//├日期驗證(第一部分)
String.prototype.isDateTime = function(){
 if(Date.parse(this)||Date.parseDate(this))
 {
  return true;
 }
 else
 {
  return false;
 }
}
String.prototype.isInteger = function()
{
 var _i = /^[-\+]?\d+$/;
 var _s = this;
 return _i.test(_s);
}
Date.prototype.toIsoDate = function()
{
 var _d = this;
 var _s;
 _Y =_d.getFullYear();
 _M = _d.getMonth() + 1;
 _D = _d.getDate();
 _H = _d.getHours();
 _I = _d.getMinutes();
 _S = _d.getSeconds();
 with(_d)
 {
  _s = [getMonth() + 1,getDate(),getHours(),getMinutes(),getSeconds()];
 }
 for(var i = 0; i < _s.length; i++)
 {
  if (_s[i].toString().length == 1)_s[i]= '0'+_s[i];
 }
  return (_Y + '-'+_s[0]+'-'+_s[1]+' '+_s[2]+':'+_s[3]+':'+_s[4])
}
//├日期驗證(第二部分)
Date.parseDate = function(str, fmt) {
 fmt = fmt||"%Y-%m-%d %H:%M";
 var today = new Date();
 var y = 0;
 var m = -1;
 var d = 0;
 var a = str.split(/\W+/);
 var b = fmt.match(/%./g);
 var i = 0, j = 0;
 var hr = 0;
 var min = 0;
 for (i = 0; i < a.length; ++i) {
  if (!a[i])
   continue;
  switch (b[i]) {
      case "%d":
      case "%e":
   d = parseInt(a[i], 10);
   break;

      case "%m":
   m = parseInt(a[i], 10) - 1;
   break;

      case "%Y":
      case "%y":
   y = parseInt(a[i], 10);
   (y < 100) && (y += (y > 29) ? 1900 : 2000);
   break;

      case "%b":
      case "%B":
   for (j = 0; j < 12; ++j) {
    if (Calendar._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { m = j; break; }
   }
   break;

      case "%H":
      case "%I":
      case "%k":
      case "%l":
   hr = parseInt(a[i], 10);
   break;

      case "%P":
      case "%p":
   if (/pm/i.test(a[i]) && hr < 12)
    hr += 12;
   else if (/am/i.test(a[i]) && hr >= 12)
    hr -= 12;
   break;

      case "%M":
   min = parseInt(a[i], 10);
   break;
  }
 }
 if (isNaN(y)) y = today.getFullYear();
 if (isNaN(m)) m = today.getMonth();
 if (isNaN(d)) d = today.getDate();
 if (isNaN(hr)) hr = today.getHours();
 if (isNaN(min)) min = today.getMinutes();
 if (y != 0 && m != -1 && d != 0)
  return new Date(y, m, d, hr, min, 0);
 y = 0; m = -1; d = 0;
 for (i = 0; i < a.length; ++i) {
  if (a[i].search(/[a-zA-Z]+/) != -1) {
   var t = -1;
   for (j = 0; j < 12; ++j) {
    if (Calendar._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { t = j; break; }
   }
   if (t != -1) {
    if (m != -1) {
     d = m+1;
    }
    m = t;
   }
  } else if (parseInt(a[i], 10) <= 12 && m == -1) {
   m = a[i]-1;
  } else if (parseInt(a[i], 10) > 31 && y == 0) {
   y = parseInt(a[i], 10);
   (y < 100) && (y += (y > 29) ? 1900 : 2000);
  } else if (d == 0) {
   d = a[i];
  }
 }
 if (y == 0)
  y = today.getFullYear();
 if (m != -1 && d != 0)
  return new Date(y, m, d, hr, min, 0);
 return today;
};
//擴展完成

//對象定義

var vform = new Object;
//獲取彈出提示的顯示位置
vform.getAbsolutePos = function(el) {
 var _p = { x: 0, y: 0 };
  do{
    _p.x += (el.offsetLeft - el.scrollLeft);
    _p.y += (el.offsetTop - el.scrollTop);
  }
   while(el=el.offsetParent)
     return _p;
      };
vform.toString = function()
{
 return("vForm表單驗證程序\n版本:1.0beta\n作者:雷曉寶\n時間:2006-07-31\n網址:http://lxbzj.com\n許可:LGPL");
}
vform.rules = new Array;
vform.rules.add = function(obj,minLength,dataType,errmsg,maxLength,rule,patams)
{
    var curlen = this.length;
        this[curlen] = [obj,minLength,dataType,errmsg,maxLength,rule,patams];
        //this[curlen] = [ 0 ,    1    ,    2   ,   3  ,   4  ,  5 ,   6  ];

    return this.length;
}
vform.init= function()
{
 if(document.getElementById(this.form_id))
 {
  //獲取表單
  var o = document.getElementById(this.form_id);
  //遍歷規則
  for(var i = 0 ;i< this.rules.length;i++)
  {
   _r = this.rules[i]
   //如果存在元素,則添加驗證程序
   if(_o = o.elements[_r[0]])
   {
    //判斷是是否必填,是否有最小長度
    if(_r[1] > 0 )
    {
     _o.required = true;//必填的含義和最小長度為1是一樣的
     _o.minLength = parseInt(_r[1]);
    }
    else
    {
     _o.required = false;
     _o.minLength = 0;
    }
    //判斷是否有最大長度;
    if(_r[4])
    {
     _o.maxLength = parseInt(_r[4]);
    }
    //添加長度驗證函數
    _o.validLength = function ()
    {
     var b =true;
     if(this.minLength)
     {
      b = (this.minLength <= this.value.length);
     }
     if(this.type == 'textarea' && this.maxLength )
     {
      b = b && (this.maxLength >= this.value.length );
     }
     return (b);
    }
    //添加驗證,進行格式驗證
    switch(_r[2])
    {
     case 'e-mail':
      _o.validate = function()
      {
       this.isvalid = this.validLength() && this.value.isEmail();
       return (this.isvalid);
      };
      break;
     case 'url':
      _o.validate = function()
      {
       if (this.value.substring(0,7) != 'http://')this.value = 'http://' +this.value;
       this.isvalid = this.validLength() && this.value.isUrl();
       return (this.isvalid);
      }
      break;
     case 'date':
      _o.validate = function()
      {
       var _d = Date.parse(this.value)||Date.parseDate(this.value);
       this.value =  _d.toIsoDate();
       
       this.isvalid = this.validLength() && this.value.isDateTime();
       return (this.isvalid);
       a=a>b?1:1;
      }
      break;
     case 'number':
      _o.validate = function()
      {
       this.isvalid = this.validLength() && this.value.isInteger();
       return (this.isvalid);

      }
      break;
     case 'any':
      _o.validate = function()
      {
       this.isvalid = this.validLength();
       return  this.isvalid
      }
      break;
     default :
      var regexp = /^\\\w+$/;
      if ( regexp.test(_r[2]))//表示必須和同表單下的某個字段的值一樣。用于重復輸入的驗證
      {
       _el = _r[2].substring(1);
       if (o.elements[_el]){
        _o.equal = _el;
        _o.validate = function()
        {
         if(_o = this.form.elements[this.equal])
         {
          if ( (_o.value == this.value) && this.validLength())
          {
           return true;
          }else {
          return false;
          }
         }else{
          alert('setup error');
         }
        
        }
       }else
       {
        alert(_el + 'is not a valid form element');
        _o.validate = function(){return true;}
       }
      }
      var regexp1 = /^\\(==|!=|>=|<=|>|<)/;
      if ( regexp1.test(_r[2]) )
      {
       _s0 = _r[2];
       _s1 = RegExp.$1;
       _s2 = _s0.replace(regexp1,'');
       _operator = _s1.substring(0);//比較操作符
       var regexp2 = /^\w+$/;
       if (regexp2.test(_s2))//是一個標志符,整數 或者變量
       {
        _o.operation = _operator+_s2;
        _o.validate = function()
        {
         _b = true;
         if (this.value.length !=0)
         {
          _b = eval(this.value+this.operation+';');
         }         
         _b = _b && this.validLength();
         return _b;
        }
       }
      };
      break;
      
    }
    //添加驗證提示(div標簽)并初始化
    var _p = vform.getAbsolutePos(_o);
    _o.tip = new tip(_r[3],vform.err_class,_p.x+_o.offsetWidth+3,_p.y);

    _o.tip.init();
    //失去焦點時,開始驗證
    _o.onblur =function(e)
    {
     if(this.minLength || this.value.length >0)
     {
      if( this.validate() )
      {
       this.tip.hide();
      }else
      {
       this.tip.show();//顯示錯誤信息
       //this.focus(); 添加這句在ie里會導致死循環 :(
       return false;
      }
     }
    }
   }
  }
 //焦點驗證可能會失敗,所以最后需要表單提交前的驗證作為最后的補充。
  document.getElementById(this.form_id).onsubmit = function()
  {
   var valid = true;
   for(i=0;i<this.elements.length;i++)
   {
    _o = this.elements[i];
    if(_o.minLength && !_o.isvalid)
    {
     _o.tip.show();
     valid = false;
    }
   }
   return valid;
  }
 }
}
//彈出提示定義
function tip(text,className,x,y)
{
 var o = document.createElement("div");
 o.style.display = "none";
 o.innerHTML = text;
 //var t = document.createTextNode(text);
 document.body.appendChild(o);
 //o.appendChild(t);
 
 this.init = function(dis)
 {
  o.className = "info";
  o.style.left = x+"px";
  o.style.top = y+"px";
  o.style.zindex = 100;
  if(dis)
  {
   o.style.display = "";
  }
  else
  {
   o.style.display = "none";
  }
 }
 this.show = function()
 {
  o.style.display = "";
 }
 this.hide = function()
 {
  o.style.display = "none";
 }
}


function start()
{
  vform.form_id = 'form1';//必須是表單的id
  vform.err_class = 'info';//出錯提示的樣式
 //驗證規則,逐條填寫
vform.rules.add('frm_name',1,'e-mail','請您按照 user@domain.com 的格式輸入電子郵件地址。<br /><span style="color:#f00">必填項目</span>');
  vform.rules.add('myweb',1,'url','請您按照 http://www.domain.com 的格式輸入您的網址。<br /><span style="color:#f00">必填項目</span>');
  vform.rules.add('dateinput',0,'date','請按2000-03-05 的格式輸入日期。<br /><span style="color:#f00">必填項目</span>');
  vform.rules.add('qq',0,'number','這必須是一個整數');
  vform.rules.add('least10',10,'any','您必須至少填寫10個<br /><span style="color:#f00">必填項目</span>');
  vform.rules.add('ok100',1,'any','這里被限制為100個字符<br /><span style="color:#f00">必填項目</span>',100);
  vform.rules.add('r_pass0',5,'any','密碼最短5位最長20位<br /><span style="color:#f00">必填項目</span>',20);
  vform.rules.add('r_pass1',5,"\\r_pass0",'確認密碼錯誤<br /><span style="color:#f00">必填項目</span>',20);
  vform.rules.add('frm_sel',1,"\\>2",'必須大于2000<br /><span style="color:#f00">必填項目</span>');
  vform.init();
 
}

</script>
</head>
<body onload="start()">

<form id="form1" name="form1" method="get" action="">
 <label for="frm_name">e-mail:
 <input name="frm_name" type="text" class="text_input" id="frm_name" title="輸入一個電子郵箱地址"/>
 </label>
 *
 <p>
  <label for="r_pass0">輸入密碼:
  <input name="r_pass0" type="text" class="text_input" id="r_pass0" title="輸入您希望的密碼 " />
  </label>
 *</p>
 <p>
  <label for="r_pass1">密碼確認:
  <input name="r_pass1" type="text" class="text_input" id="r_pass1" title="將密碼確認一次" />
  </label>
 *</p>
 <p>
  <label for="frm_sel">選擇:
  <select name="frm_sel" id="frm_sel" title="請選擇一個答案">
   <option value="0">請選擇一個答案</option>
   <option value="1" selected="selected">1000</option>
   <option value="2">2000</option>
   <option value="3">3000</option>
   <option value="4">4000</option>
   <option value="5">5000</option>
   <option value="6">6000</option>
  </select>
</label>
 *</p>
 <p>
  <label for="input3">輸入網址:
  <input name="myweb" type="text" class="text_input" id="input3" title="輸入一個網址" onmousemove="" value="http://" maxlength="100"/>
  </label>
 *</p>
 <p>
  <label for="dateinput">輸入日期
  <input name="dateinput" type="text" class="text_input" title="輸入一個日期" id="dateinput"/>
</label>
 *</p>
 <p>
  <label for="mub">輸入數字
  <input name="qq" type="text" class="text_input" title="填寫數字" id="mub"/>
  </label>
 </p>
 <p>
  <label for="len">輸入任意但長度限制為10個
  <input name="least10" type="text" class="text_input" maxlength="88" id="len"/>
  *
  </label>
 </p>
 <p>
  <label for="text">只能輸入100個
  <textarea name="ok100" cols="40" rows="5" id="text" title="詳細內容"></textarea>
  *
  </label>
 </p>
 <p>
  <input type="submit" name="Submit" value="提交" />
  <button onclick="alert(vform)" >關于驗證程序</button>
 </p>
</form>
<!--具體的日期設置,必須放在body的結束標簽前面-->
<script type="text/javascript">
  vform .init();
    Calendar.setup({
   inputField     :    "dateinput",   // 把這個改成你需要的 id
   ifFormat       :    "%Y-%m-%d %H:%M", // format of the input field
   showsTime      :    true,
   //button     :    "dateinput_btn",
   timeFormat     :    "24"
   });
 </script>
<!--END具體的日期設置,必須放在body的結束標簽前面-->
<div class="title">
 <h1>vForm1.0beta</h1>
 <ul>
  <li>作者:雷曉寶</li>
  <li>時間:2006-08-08</li>
  <li>網址:http://lxbzj.com</li>
  <li>e-mail:lxbzmy@163.com</li>
  <li>許可:LGPL</li>
 </ul>
 <h2>功能簡述:</h2>
 <ol>
   <li>
     <h3>驗證:</h3>
     <ul>
       <li>http地址。</li>
          <li>時間日期</li>
       <li>e-mail</li>
       <li>數字</li>
       <li>字符長度檢查</li>
       <li>一項輸入與另一項輸入比較(例如:密碼的確認輸入)</li>
       <li>大小比較(只能有一個比較符號)</li>
        </ul>
   </li>
      <li>
        <h3>特點</h3>
        <ul>
          <li>擴展容易,可以方便的添加自己需要的驗證方式</li>
          <li>兼容性好(ie5,6 firefox,oprea)。</li>
        <li>可用性好,沒有使用alert()來彈出提示;</li>
        </ul>
      </li>
  </ol>
 <p> </p>
 <h2>使用方法</h2>
 <p>使用時,需要定義一個出錯提示框的樣式,本例的樣式為:<code>div.info {
     width: 170px;<br />
    overflow:visible;<br />
    height:auto;<br />
    font-size: small;<br />
    position: absolute;<br />
    background-color: #FFffdd;<br />
    border: 1px solid #000;<br />
    filter:progid:DXImageTransform.Microsoft.Shadow(color=#111111,direction=135,strength=3);<br />
    padding: 5px;<br />
    }</code></p>
 <p>然后在網頁&lt;head&gt;部分中添加<code>&lt;script type="text/javascript" src="calendar/calendar.js"&gt;&lt;/script&gt;</code><br />
   ,然后可以寫一個函數設置表單名稱,驗證規則,<code>function start()<br />
   {
   <br />
   vFormvform.form_id = 'form1';<br />
  vform.err_class = 'info';<br />
  // (obj,required(true/false),dataType,errmsg,minlen,maxlen,rule,patams)<br />
  //驗證規則,逐條填寫<br />
  vform.rules.add('frm_name',1,'e-mail','請您按照 user@domain.com 的格式輸入電子郵件地址。&lt;br /&gt;&lt;span style="color:#f00"&gt;必填項目&lt;/span&gt;');<br />
  vform.rules.add('myweb',1,'url','請您按照 http://www.domain.com 的格式輸入您的網址。&lt;br /&gt;&lt;span style="color:#f00"&gt;必填項目&lt;/span&gt;');<br />
  vform.rules.add('dateinput',0,'date','請按2000-03-05 的格式輸入日期。&lt;br /&gt;&lt;span style="color:#f00"&gt;必填項目&lt;/span&gt;');<br />
  vform.rules.add('qq',0,'number','這必須是一個整數');<br />
  vform.rules.add('least10',10,'any','您必須至少填寫10個&lt;br /&gt;&lt;span style="color:#f00"&gt;必填項目&lt;/span&gt;');<br />
  vform.rules.add('ok100',1,'any','這里被限制為100個字符&lt;br /&gt;&lt;span style="color:#f00"&gt;必填項目&lt;/span&gt;',100);<br />
   vform.init();<br />
   }</code>最后為body添加onload事件。   <code>   &lt;body onload="start();"&gt;
 </code></p>
 <p> </p>
</div>
</body>
</html>

bgm 發表在 痞客邦 留言(0) 人氣()

CODE:

一般的checkbox<input type=checkbox >
<br/>
比較不同的checkbox<input type=checkbox style="position:absolute;clip: rect(5 16 16 5)">
<br/>
平面checkbox--&gt;<input type=checkbox style="position:absolute;clip: rect(6 15 15 6)">
<br/>
外凸checkbox--&gt;<input type=checkbox style="position:absolute;clip: rect(6 17 17 6)">
<br/>
一般的select
<div style="width:108px; height:19px; overflow: hidden; border: 1 solid black">
<div style="position:absolute; left:-2; top:-2; width:171px; height:50px; clip: rect(2 108 19 2)">
    <select name="select">
      <option selected>aaaaaaaaaaaa</option>
      <option>bbbbbbbbbbbb</option>
      <option>cccccccccccc</option>
      <option>dddddddddddd</option>
    </select>
  </div>
 </div>
<br/>
平面的select<select name="menu1" style="position:absolute;clip: rect(6 17 17 6)">
    <option>111111</option>
    <option>222222</option>
    <option>333333</option>
    <option>444444</option>
    </select>
<br/>
外凸的select<select name="menu1" style="position:absolute;clip: rect(2 50 30 2)">
    <option>111111</option>
    <option>222222</option>
    <option>333333</option>
    <option>444444</option>
  </select>
</br></br>


語法︰
 
clip : auto | rect ( number number number number )
 
參數︰
 
auto :  對象無剪下
rect ( number number number number ) :  依據上-右-下-左的順序提供自對象左上角為(0,0)坐標計算的四個偏移數值,其中任一數值都可用auto取代,即此邊不剪下
 
說明︰
 
檢索或設定對象的可視欄位。欄位外的部分是透明的。
必須將position的值設為absolute,此屬性方可使用。
自IE5開始,此屬性在MAC平臺上可用。
對應的腳本特性為clip。請參閱我編寫的其它書目。

bgm 發表在 痞客邦 留言(0) 人氣()

很簡單利用label就能達成

<label for="box"><input type=checkbox name=box id=box value="box">點這裡的文字看看!</label>

bgm 發表在 痞客邦 留言(0) 人氣()

可修改內容的下拉式選單


<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>可修改內容的下拉式選單</TITLE>
<script language="JavaScript">
<!--
function catch_keydown(sel)
{
switch(event.keyCode)
{
case 13:
//Enter;
sel.options[sel.length] = new Option("","",false,true);
event.returnValue = false;
break;
case 27:
//Esc;
alert("text:" + sel.options[sel.selectedIndex].text + ", value:" + sel.options[sel.selectedIndex].value + ";");
event.returnValue = false;
break;
case 46:
//Delete;
if(confirm("刪除當前選項!?"))
{
sel.options[sel.selectedIndex] = null;
if(sel.length>0)
{
sel.options[0].selected = true;
}
}
event.returnValue = false;
break;
case 8:
//Back Space;
var s = sel.options[sel.selectedIndex].text;
sel.options[sel.selectedIndex].text = s.substr(0,s.length-1);
event.returnValue = false;
break;
}

}
function catch_press(sel)
{
sel.options[sel.selectedIndex].text = sel.options[sel.selectedIndex].text + String.fromCharCode
sel.options[sel.selectedIndex].value = sel.options[sel.selectedIndex].text;
event.returnValue = false;
}
//-->
</script>
</HEAD>
<body bgcolor="#fef4d9">
按Enter輸入新內容,按DEL刪除選中內容,按ESC顯示選中內容;可輸入資料<br> 
可惜的是只能新增修改option的文字(text)項,如果有新增選項的話,option的值(value)會和文字相同
post回去的話除非server端程式要作動態修正,否則選單的選項不會改變
<form method=post>
<select name=s1 onkeydown="catch_keydown(this);" onkeypress="catch_press(this);" style="font-size:12px;">
<option>選項1</option>
<option>選項2</option>
<option>選項3</option>
<option>選項4</option>
<option>選項5</option>
</select>
<br/>
<input type=submit name=btn class="btn_query" value="送出">
<br/>
<%if Request.Form("s1") <> "" then Response.Write "選項內容為:" & Request.Form("s1")%>
</form>
</BODY>
</HTML>

bgm 發表在 痞客邦 留言(0) 人氣()


如何在VB6裡把UTF-8格式的繁體中文字讀出,而不成亂碼? 

寫程式讀檔35 可能會遇到有UTF-8的編碼..
不幸的是.. VB6 讀進的中文字會變亂碼

亦無法像VS.Net 一樣可輕易的讀取 ..
因此在這,小弟提供另兩個解決方案分享給大家參考 ( API )

1.
如果是 XML 檔案或資料 , 可透過 M$ DOM 物件來讀入文件

2.
M$ 開發工具寫資料庫的人, 都應該知道 ADO
       
ADODB 裡面有個Stream物件 , 可透過該物件讀檔,
       
再指定Charset,之後即可透過ReadText方法取回資料
       
如此就能解決編碼的問題囉 !

Sample :

Dim objStream As Object
Set objStream = CreateObject("ADODB.Stream")

With objStream
        .Type = 2
        .Mode = 3 
        .Open 
        .Charset = "UTF-8" ' 或其他編碼 
        .LoadFromFile "
檔案路徑+名稱
         取回結果 = .ReadText 
        ' PS :
也可透過 .SaveToFile 方法把檔案存檔 
        .Close
End With 

bgm 發表在 痞客邦 留言(0) 人氣()

就一般而論,(靜態)網頁通常不會包含太多腳本語言(scritp);或許至少不會包含太多腳本語言而影嚮到網頁的速度。但是當網頁愈來愈往應用軟體方式發展時,網頁內腳本語言的效率就會大大的影嚮到網頁的速度,而如何增進腳本語言的效率也更形重要。

一般應用程式都是透過編譯器將原始碼編譯成可執行檔,編譯器在進行編譯時可以使用較多時間針對效能面作出調整,而產生較有效率的程式。但是網頁上的程式就沒有如此的空閒。因為他們需要在多種瀏覽器、平台及多樣的架構上執行,所以不能預先編譯好。當接到一個腳本指令時,瀏覽器必須快速載入、解釋和編譯,並讓最後產生出來的應用程式能運作得和桌面後用程式一樣順暢。這些腳本語言被希望能在各懂不同的裝置上使用,從一台普通的桌上型電腦到行動電話。

瀏覽器相當擅長完成上述的事情,而且在現今的瀏覽器中Opera攡有一個非常快速的腳本語言引擎。不過瀏覽器還是有它他的限憲,而這也是網頁開發者必須要去完成的。確保一個網頁應用程式能執行的儘可能的迅速可能只是把迴圈換成另外一種寫法、讓結合型的類別改為三個分開的類別、或只是加入可能用到的腳本。

本篇文章將告訴你如何透過幾個簡單的修改而增進網頁應用程式的效率。範圍包含ECMAScript-它是JavaScritp,DOM與文件載入的核心語言。

bgm 發表在 痞客邦 留言(0) 人氣()

dev.opera.com/articles/view/efficient-javascript/

知名瀏覽器 Opera 的 DEV.Opera 網站上的文章 教你如何寫有出效率的 JavaScript 。 

將會在此貼出自已翻譯成中文版

bgm 發表在 痞客邦 留言(0) 人氣()