Sina's financial channel has always felt good. But because of the recent slow speed, the Web page is always open when viewing stock information. have been studying Ajax for several days, so I made a page with jquery to automatically read real-time data on Sina stock.
Accustomed to using prototype, replace the script part of the code.
Copy code code as follows:
<script type= "Text/javascript" src= "prototype.js" ></script> <script type= "Text/javascript" .... function Ajaxrequest () ... {var myajax = new Ajax.request (' http://hq.sinajs.cn/list=sh000001,sh601939,sh600016,sh600528,sh600667,sh601390, sh601398,sh601857,sh600028 ', ...
{method: ' Get ', oncomplete:setdata}); } function SetData (response) ...
{var contents = Response.responsetext;
var stocks = Contents.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;
$ (' a ' +i). InnerHTML = code;
$ (' B ' +i). InnerHTML = name;
$ (' C ' +i). InnerHTML = Curr_f; if (Curr_f > Yest_f) ... {$ (' C ' +i). InnerHTML = "<font color= ' Red ' > "+ curr_f +" </font> "; else if (Curr_f < Yest_f) ...
{$ (' C ' +i). InnerHTML = "<font color= ' green ' >" + curr_f + "</font>"; else ...
{$ (' C ' +i). InnerHTML = Curr_f;
} $ (' d ' +i). InnerHTML = Tday_f;
$ (' E ' +i). InnerHTML = Yest_f; if (Temp_f > 0) ...
{$ (' F ' +i). InnerHTML = "<font color= ' Red ' >" + temp_f.tofixed (2) + "</font>";
$ (' G ' +i). InnerHTML = "<font color= ' Red ' >" + ((temp_f/yest_f) *). ToFixed (2) + "</font>%"; else if (Temp_f < 0) ...
{$ (' F ' +i). InnerHTML = "<font color= ' green ' >" + temp_f.tofixed (2) + "</font>";
$ (' G ' +i). InnerHTML = "<font color= ' green ' >" + ((temp_f/yest_f) *). ToFixed (2) + "</font>%"; else ...
{$ (' F ' +i). InnerHTML = temp_f.tofixed (2);
$ (' G ' +i). InnerHTML = ((temp_f/yest_f) *). ToFixed (2) + "%";
} $ (' H ' +i). InnerHTML = Temp3.split (', ') [4];
$ (' I ' +i). InnerHTML = Temp3.split (', ') [5]; }} function Pageinit () ...
{Window.setinterval ("ajaxrequest ()", 3000); };/script>
Of course, the page part can be automatically generated by the script, as well as the page dynamically increase and decrease stock information and other functions, and so on later modify it.