CopyCode The Code is as follows: <HTML>
<Head>
<Title> Ajax test </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<SCRIPT type = "text/JavaScript" src = "jquery. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">...
Function ajaxrequest ()...{
VaR url = $ ("# stockurl"). Val () + $ ("# stockinit"). Val ();
$. Ajax (...{
URL: URL,
Type: 'get ',
Datatype: 'html ',
Timeout: 2000,
Success: function (response )...{
VaR stocks = response. Split (';');
For (VAR I = 0; I <stocks. Length-1; I ++ )...{
VaR content = stocks [I];
VaR temp1 = content. Split ('=') [0];
VaR temp2 = content. Split ('=') [1];
VaR code = temp1.substr (temp1.length-6, 6 );
VaR temp3 = temp2.replace ('"','');
VaR name = temp3.split (',') [0];
VaR tday_f = temp3.split (',') [1];
VaR yest_f = temp3.split (',') [2];
VaR curr_f = temp3.split (',') [3];
VaR temp_f = curr_f-yest_f;
Certificate ('{a'{ I }.html (CODE );
Certificate ('{ B '{ I }.html (name );
If (curr_f> yest_f )...{
Certificate ('{c'{ I }.html ("<font color = 'red'>" + curr_f + "</font> ");
} Else if (curr_f <yest_f )...{
Certificate ('{c'{ I }.html ("<font color = 'green'>" + curr_f + "</font> ");
} Else ...{
Certificate ('{c'{ I }.html (curr_f );
}
Certificate ('mongod'{ I }.html (tday_f );
Certificate ('{e'{ I }.html (yest_f );
If (temp_f> 0 )...{
('{F'{ I }.html ("<font color = 'red'>" + temp_f.tofixed (2) + "</font> ");
Certificate ('{g'{ I }.html ("<font color = 'red'>" + (temp_f/yest_f) * 100). tofixed (2) + "</font> % ");
} Else if (temp_f <0 )...{
Certificate ('{f'{ I }.html ("<font color = 'green'>" + temp_f.tofixed (2) + "</font> ");
Certificate ('{g'{ I }.html ("<font color = 'green'>" + (temp_f/yest_f) * 100). tofixed (2) + "</font> % ");
} Else ...{
('{F'{ I }.html (temp_f.tofixed (2 ));
Certificate ('{g'{ I }.html (temp_f/yest_f) * 100). tofixed (2) + "% ");
}
('{H'{ I }.html (temp3.split (',') [4]);
('{ I '{ I }.html (temp3.split (',') [5]);
}
}
});
}
$ (Document). Ready (function ()...{
VaR stocks = $ ("# stockinit"). Val (). Split (',');
For (VAR I = 0; I <stocks. length; I ++ )...{
Addrows ();
}
$ ("# Insrow"). Click (function ()...{
VaR stockcd = $ ("# stockid"). Val ();
If (stockcd = "")...{
Alert ("The Stock Code cannot be blank! ");
$ ("# Stockid"). Focus ();
Return;
}
If (stockcd. length! = 6 )...{
Alert ("the stock code can only be 6 digits! ");
$ ("# Stockid"). Focus ();
Return;
}
VaR DIV = 'sh ';
If (document. getelementbyid ("sz_id"). Checked)... {DIV = "SZ ";}
VaR stocks = $ ("# stockinit"). Val ();
$ ("# Stockinit"). Val (stocks + "," + Div + stockcd );
Addrows ();
});
$ ("# Delrow"). Click (function ()...{
VaR table = Document. getelementbyid ("tableid ");
VaR Index = table. Rows. length;
If (index <2 )...{
Alert ("No rows can be deleted! ");
} Else ...{
Table. deleterow (index-1 );
VaR stockvalue = $ ("# stockinit"). Val ();
VaR COUNT = stockvalue. Split (','). length;
If (COUNT = 1 )...{
Stockvalue = "";
} Else ...{
Stockvalue = stockvalue. substr (0, stockvalue. Length-9 );
}
$ ("# Stockinit"). Val (stockvalue );
}
});
Windows. setinterval ("ajaxrequest ()", 3000 );
});
Function addrows ()...{
VaR table = Document. getelementbyid ("tableid ");
VaR Index = table. Rows. length;
VaR STR = "";
VaR ROW = index-1;
STR + = '<tr class = "tr_cls">'
STR + = '<TD align = "center"> <span id = "' +" A "+ row + '"> </span> </TD>'
STR + = '<TD align = "center"> <span id = "' +" B "+ row + '"> </span> </TD>'
STR + = '<TD align = "center"> <span id = "' +" C "+ row + '"> </span> </TD>'
STR + = '<TD align = "center"> <span id = "' +" D "+ row + '"> </span> </TD>'
STR + = '<TD align = "center"> <span id = "' +" E "+ row + '"> </span> </TD>'
STR + = '<TD align = "center"> <span id = "' +" F "+ row + '"> </span> </TD>'
STR + = '<TD align = "center"> <span id = "' +" G "+ row + '"> </span> </TD>'
STR + = '<TD align = "center"> <span id = "' +" H "+ row + '"> </span> </TD>'
STR + = '<TD align = "center"> <span id = "' +" I "+ row + '"> </span> </TD>'
STR + = '</tr> ';
$ ("# Tablebody"). append (STR );
}
</SCRIPT>
<Style>...
. Tr_cls {...}{
Height: 30px;
Font-size: 16px;
Font-family: "Times New Roman", times, Serif;
Background-color: # ffffcc
}
</Style>
</Head>
<Body>
<Form>
<Input type = "hidden" id = "stockurl" value = "http://hq.sinajs.cn/list="/>
<Input type = "hidden" id = "stockinit" value = "sh000001, sz399001, sh601939, sh600016, clerk, sh600667, sh601390, sh601857, sz000532, sh600019, sh601111, clerk, sh601006, sh60133, sh601398, sh601988, sh601328 "/>
<Table width = "800" border = "0" align = "center" cellpadding = "0" cellspacing = "0">
<Tr>
<TD width = "115px">
Code: <input type = "text" id = "stockid" size = "6">
</TD>
<TD width = "150px">
Differentiation: shanghai <input type = "radio" name = "rad" id = "sh_id" Checked> deep evidence <input type = "radio" name = "rad" id = "sz_id">
</TD>
<TD width = "40px">
<Input type = "button" id = "insrow" value = "Row appending">
</TD>
<TD width = "495px">
<Input type = "button" id = "delrow" value = "Row pruning">
</TD>
</Tr>
<Tr>
<TD colspan = "4">
<Div style = "overflow-Y: Scroll; overflow-X: auto; Height: 392px; width: 817px">
<Table id = "tableid" width = "800" border = "1" align = "center" cellpadding = "0" cellspacing = "0" bordercolor = "#000000">
<Tr bgcolor = "# 3399ff" Height = "30px">
<TH scope = "col"> stock code </Th>
<TH scope = "col"> stock name </Th>
<TH scope = "col"> current price </Th>
<TH scope = "col"> opened today </Th>
<TH scope = "col"> close yesterday </Th>
<TH scope = "col"> current price difference </Th>
<TH scope = "col"> increase/decrease </Th>
<TH scope = "col"> maximum price </Th>
<TH scope = "col"> lowest price </Th>
</Tr>
<Tbody id = "tablebody">
</Tbody>
</Table>
</Div>
</TD>
</Tr>
</Table>
</Form>
</Body>
</Html>