Author: caoxicao
Source: http://blog.csdn.net/caoxicao
Code Analysis:
Function checkserialnum (Whatid, what, retailer, curr, whse)
{If (form1.salesman. value = "")
{
Alert ("select a store first ");
Return;
}
If (event. keycode = 13)
{
VaR oxmlhttp = new activexobject ("Microsoft. XMLHTTP ");
Oxmlhttp. Open ("Post", "qrysn. asp? Serialnum = "+ What +" & retailer = "+ retailer +" & curr = "+ curr +" & whse = "+ whse, false );
Oxmlhttp. Send ();
If (Unescape (oxmlhttp. responsetext) = "wrong ")
{
Alert ('not found! ');
Eval ("window. form1.serialnum" + Whatid + ". Select ()");
Eval ("window. form1.serialnum" + Whatid + ". Focus ()");
}
Else
{
VaR strserial
Strserial = Unescape (oxmlhttp. responsetext );
VaR serialnum
// Alert (strserial );
Serialnum = strserial. Split ("*_*");
Eval ("window. form1.serialnum" + Whatid + ". value =/" "+ String (serialnum [0]) + "/";");
Eval ("window. form1.productcode" + Whatid + ". value =/" "+ serialnum [1] + "/";");
Eval ("window. form1.whselocation" + Whatid + ". value =/" "+ serialnum [2] + "/";");
Eval ("window. form1.price" + Whatid + ". value =/" "+ serialnum [3] + "/";");
Eval ("window. form1.maxprice" + Whatid + ". value =/" "+ serialnum [4] + "/";");
Eval ("window. form1.minprice" + Whatid + ". value =/" "+ serialnum [5] + "/";");
Eval ("window. form1.productname" + Whatid + ". value =/" "+ serialnum [6] + "/";");
Eval ("window. form1.lottracked" + Whatid + ". value =/" "+ serialnum [7] + "/";");
Eval ("window. form1.lotlen" + Whatid + ". value =/" "+ serialnum [8] + "/";");
Eval ("window. form1.serialtracked" + Whatid + ". value =/" "+ serialnum [9] + "/";");
Eval ("window. form1.seriallen" + Whatid + ". value =/" "+ serialnum [10] + "/";");
Eval ("window. form1.vendorid" + Whatid + ". value =/" "+ serialnum [11] + "/";");
Eval ("window. form1.stocktype" + Whatid + ". value =/" "+ serialnum [12] + "/";");
// Add rows dynamically
// Begin
Id = Whatid + 1
VaR OBJ = eval ("goodtr" + Whatid );
VaR objdiv = eval ("tdtr1 ");
VaR re0;
Re0 =/(serialnum | productcode | productname | qty | price | whselocation | cash | customerpay | commitment | lottracked | serialtracked | lotlen | seriallen | maxprice | minprice | vendorid | stocktype | descriptr) (/()? (')? [1-9] [0-9]? (')? (/))? /G;
VaR RE1;
RE1 =/> [1-9] [0-9]? </;
VaR modifiedhtml;
Modifiedhtml = obj. innerhtml;
Modifiedhtml = modifiedhtml. Replace (re0, "$1" + "$2" + "$3" + String (ID) + "$4" + "$5 ");
Modifiedhtml = modifiedhtml. Replace (RE1, "> <");
VaR addhtml;
Addhtml = "<Table width =/" 100%/"> <tr id = goodtr" + String (ID) + "> ";
Addhtml = addhtml + modifiedhtml;
Addhtml = addhtml + "</tr> </table>"
Objdiv. insertadjacenthtml ("beforeend", addhtml );
Eval ("form1.serialnum" + ID + ". value = ''");
Eval ("form1.productcode" + ID + ". value = ''");
Eval ("form1.productname" + ID + ". value = ''");
Eval ("form1.qty" + ID + ". value = '1 '");
Eval ("form1.price" + ID + ". value = ''");
Eval ("form1.whselocation" + ID + ". value = ''");
Eval ("form1.cash" + ID + ". value = ''");
Eval ("form1.customerpay" + ID + ". value = ''");
Eval ("form1.commitment" + ID + ". value = ''");
Eval ("form1.lottracked" + ID + ". value = ''");
Eval ("form1.serialtracked" + ID + ". value = ''");
Eval ("form1.lotlen" + ID + ". value = ''");
Eval ("form1.seriallen" + ID + ". value = ''");
Eval ("form1.maxprice" + ID + ". value = ''");
Eval ("form1.minprice" + ID + ". value = ''");
Eval ("form1.vendorid" + ID + ". value = ''");
Eval ("form1.stocktype" + ID + ". value = ''");
Eval ("window. form1.serialnum" + ID + ". Focus ()");
Window. form1.maxline. value = Whatid;
// The maxline value is of little significance to this program, but many programs are already in use.
// And the value is fixed before and is now a variable. Pai_^
// End
}
}
}
This section mainly analyzes the dynamic addition technology.
After comparing many techniques for dynamically adding rows or columns, the current method is the most concise.
Innerhtml can only add content in tables or <div> </div>, but cannot dynamically add <tr> </tr> (at that time, this place almost drove me crazy !)
Therefore, in the row to be added, you can set it as follows:
<Tr>
<TD colspan = 10 Id = tdtr <% = I %>
& Lt; table width = "100%" & gt;
<Tr id = goodtr <% = I %>
<TD> </TD>
</Tr>
</Table>
</TD>
</Tr>
In addition, insertadjacenthtml and innerhtml are inserted first, and the second is assigned a value.
Prototype: insertadjacenthtml (swhere, stext)
Parameters:
Swhere: specifies where HTML tag statements are inserted. Four values can be used:
1. beforebegin: before the start of the tag
2. afterbegin: inserted after the tag starts Marking
3. beforeend: insert to the end tag of the tag.
4. afterend: insert to the end tag of the tag.
==================================
VaR OBJ = eval ("goodtr" + Whatid); // first define an object to be inserted
VaR objdiv = eval ("tdtr1"); // defines a tag location
VaR modifiedhtml;
Modifiedhtml = obj. innerhtml; // insert OBJ
Modifiedhtml = modifiedhtml. Replace (re0, "$1" + "$2" + "$3" + String (ID) + "$4" + "$5 ");
Modifiedhtml = modifiedhtml. Replace (RE1, "> <"); // the preceding two rows are used to format the inserted content.
VaR addhtml;
Addhtml = "<Table width =/" 100%/"> <tr id = goodtr" + String (ID) + "> ";
Addhtml = addhtml + modifiedhtml;
Addhtml = addhtml + "</tr> </table>" // the preceding three rows are the HTML content to be inserted.
Objdiv. insertadjacenthtml ("beforeend", addhtml); // insert addhtml content at the objdiv tag
======================================
Analysis of REO, RE1, two regular expressions.
VaR re0;
Re0 =/(serialnum | productcode | productname | qty | price | whselocation | cash | customerpay | commitment | lottracked | serialtracked | lotlen | seriallen | maxprice | minprice | vendorid | stocktype | descriptr) (/()? (')? [1-9] [0-9]? (')? (/))? /G;
// Optional G parameter at the end, which indicates that all matching strings are searched in each line (instead of the first matching string by default ).
// You can add an I parameter at the end to ignore the case sensitivity.
// [1-9] [0-9]? Indicates matching two digits
// [1-9] [0-9] indicates matching any number of digits
/// <. *>/And <(. *)>/are the same. (.) is often used to represent periods.
// Its Meaning: match all content starting from the less than sign (<) to the greater than sign at the end of the mark.
// If/<. *?> /, Minimum match, indicating: Only one // In '*', '+', or '? 'Place after the qualifier '? ', This expression is converted from greedy match to non-greedy or minimum match.
// The above re0 indicates: serialnum | productcode... and all strings ('num') or (Num), such as serialnum5
//
//
//
//
VaR RE1;
RE1 =/> [1-9] [0-9]? </;
Modifiedhtml = modifiedhtml. Replace (re0, "$1" + "$2" + "$3" + String (ID) + "$4" + "$5 ");
Modifiedhtml = modifiedhtml. Replace (RE1, "> <");
--------Game Over--------