當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JavaScript随笔一篇
生活随笔
收集整理的這篇文章主要介紹了
JavaScript随笔一篇
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
作者:Truly
日期:2007.7.31
近期Post了不少Javascript文章,還是收到不少支持,你們的回復是我寫下去的動力,謝謝你們!
剛剛研究了一下新浪的財經板塊,其中對股票數據的處理真的是跟我的MVC模式的文章不謀而合啊。我順手寫了2段代碼,大家看看。
Stock.html <!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.0?Transitional//EN">
<html>
<head>
????<title>Truly's?stock</title>
????<script?src=data.js></script>
????<style>
/*?change_color?*/
.incolor{color:#FF0000;}
.decolor{color:#008000;}
#itemTickettime
{
????font-size:12px;
}
span,div{font-size:12px;}
????</style>
</head>
<body>
<script?id=vsdata></script>
<input?id=mystock?value='000001'><br><br>
<input?id='sh'?type=radio?name='type'?checked?value=1>sh<input?type=radio?name='type'?value=2>sz
<br><br>
<input?type=button?value='?Go?'?onclick='loadMyStockList()'>?<input?type=button?value='?Stop?'?onclick='stopFresh()'><br><br>
<div?class="tbtb01">
<span?id='name'></span>
<div><span?id="itemMarket">-</span>?<span?id='code'></span>? 昨收<span?id='s'></span> 今開<span?id='k'></span></div>
</div>
<div?class="tbtb02">
<h3?id="itemCurrent"?class="incolor">-</h3>
<span?class="fRed01"?id="itemcurrprice">-</span> <span?class="fRed01"?id="itemDiffpercent">-</span>
<span?id="itemTickettime">-</span>
</div>
</body>
</html>
Data.js var?AppConf?=?{
????Interval_1s:1*1000,
????Interval_AginReq:500,
????url:'http://hq.sinajs.cn/format=js&func=S_Finance.upconstants.setData();&list='
};
function?$(id){return?document.getElementById(id);};
function?$C(nodeName){return?document.createElement(nodeName);};
function?gt(){if($('sh').checked)?return?'sh'+$('mystock').value;return?'sz'+$('mystock').value;}
var?timer;
var?itemCurrent;
function?loadMyStockList()
{
????itemCurrent?=?$("itemCurrent");
????fullcode=gt();
????clearInterval(timer);
????timer?=?setInterval("Truly.load_data_script(AppConf.url+gt(),'vsdata');",?1000);
}
function?stopFresh()
{
????clearInterval(timer);
}
var?jk,zs;
var?currprice,currnum;
var?_A=function(t,c){t.appendChild(c)};
var?fullcode?=?'sh600390';
var?Truly?=?{
????load_data_script:function(url,idname)
????{
????????var?h?=?new?Date().getHours();
????????var?m?=?new?Date().getMinutes();
????????if(h?<?9?||?(h>15)?||?(h?==?15&&?m>10))?stopFresh();
????????var?obj=$(idname);
????????if(obj){obj.parentNode.removeChild(obj);};
????????var?newscript=$C("script");
????????newscript.type="text/javascript";
????????newscript.src=url;
????????newscript.id=idname;
????????_A(document.body,newscript);
????}
}
var?S_Finance={};
S_Finance.upconstants={itemTickettime:null,servertime:null,
setData:function(){
????this.itemTickettime=$("itemTickettime").innerHTML;
????eval("this.hq_str_symbol?=?hq_str_"+fullcode);
????if(this.hq_str_symbol!=null?&&?this.hq_str_symbol!=undefined?&&?this.hq_str_symbol!="undefined"?&&?this.hq_str_symbol!="")
????{
????????this.chgedary=new?Array();
????????this.chgedarylen=0;
????????this.cacheidx=0;
????????this.setValue(this.hq_str_symbol);
????????this.initflag=1;
????}
????else
????{
????????setTimeout(this._updata._Bind(this),AppConf.Interval_AginReq);
????????return?true;
????};
????this.setFlash=function(tid)
????{
????????var?_tidColor=$(tid).style.color;
????????setTimeout(function(){$(tid).style.color="#000000";},400);
????????setTimeout(function(){$(tid).style.color=_tidColor;},600);
????????setTimeout(function(){$(tid).style.color="#000000";},800);
????????setTimeout(function(){$(tid).style.color=_tidColor;},1000);
????};
????if(this.itemTickettime!=$("itemTickettime").innerHTML)
????{
????????$("itemcurrprice").style.fontFamily="Arial";
????????$("itemcurrprice").style.fontSize="11px";
????????$("itemDiffpercent").style.fontFamily="Arial";
????????$("itemDiffpercent").style.fontSize="11px";
????????this.setFlash("itemCurrent");
????????this.setFlash("itemcurrprice");
????????this.setFlash("itemDiffpercent");
????};
????return?true;
},
????setValue:function(data)
????{
????????var?dataContent=data;
????????if(dataContent){
????????????dataContent.replace("\r","");dataContent.replace("\n","");
????????????var?dataArray=dataContent.split(",");
????????????var?arrayLen=dataArray.length;
????????}
????????$("itemTickettime").innerHTML=dataArray[30]+"?"+dataArray[31];
????????$("itemCurrent").innerHTML=dataArray[3];
????????$("name").innerHTML=dataArray[0];
????????$("code").innerHTML=fullcode;
????????currprice?=?(dataArray[3]*1000-dataArray[2]*1000)/1000;
????????currnum=(dataArray[3]*1000-dataArray[2]*1000)/(10*dataArray[2]);
????????$("itemcurrprice").innerHTML=currprice;
????????$("itemDiffpercent").innerHTML=?Math.round(currnum*100)/100?+?'%';
????????jk=dataArray[1];
????????zs=dataArray[2];
????????
????????$("k").innerHTML=jk;
????????$("s").innerHTML=zs;
????????if(dataArray[3]?>zs)?itemCurrent.style.color='#FF0000';
????????else?if(dataArray[3]?==zs)?itemCurrent.style.color='#000000';
????????else?itemCurrent.style.color='#008000';
????????$("itemcurrprice").style.color=itemCurrent.style.color;
????????$("itemDiffpercent").style.color=itemCurrent.style.color;
????}
}
日期:2007.7.31
近期Post了不少Javascript文章,還是收到不少支持,你們的回復是我寫下去的動力,謝謝你們!
剛剛研究了一下新浪的財經板塊,其中對股票數據的處理真的是跟我的MVC模式的文章不謀而合啊。我順手寫了2段代碼,大家看看。
Stock.html <!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.0?Transitional//EN">
<html>
<head>
????<title>Truly's?stock</title>
????<script?src=data.js></script>
????<style>
/*?change_color?*/
.incolor{color:#FF0000;}
.decolor{color:#008000;}
#itemTickettime
{
????font-size:12px;
}
span,div{font-size:12px;}
????</style>
</head>
<body>
<script?id=vsdata></script>
<input?id=mystock?value='000001'><br><br>
<input?id='sh'?type=radio?name='type'?checked?value=1>sh<input?type=radio?name='type'?value=2>sz
<br><br>
<input?type=button?value='?Go?'?onclick='loadMyStockList()'>?<input?type=button?value='?Stop?'?onclick='stopFresh()'><br><br>
<div?class="tbtb01">
<span?id='name'></span>
<div><span?id="itemMarket">-</span>?<span?id='code'></span>? 昨收<span?id='s'></span> 今開<span?id='k'></span></div>
</div>
<div?class="tbtb02">
<h3?id="itemCurrent"?class="incolor">-</h3>
<span?class="fRed01"?id="itemcurrprice">-</span> <span?class="fRed01"?id="itemDiffpercent">-</span>
<span?id="itemTickettime">-</span>
</div>
</body>
</html>
Data.js var?AppConf?=?{
????Interval_1s:1*1000,
????Interval_AginReq:500,
????url:'http://hq.sinajs.cn/format=js&func=S_Finance.upconstants.setData();&list='
};
function?$(id){return?document.getElementById(id);};
function?$C(nodeName){return?document.createElement(nodeName);};
function?gt(){if($('sh').checked)?return?'sh'+$('mystock').value;return?'sz'+$('mystock').value;}
var?timer;
var?itemCurrent;
function?loadMyStockList()
{
????itemCurrent?=?$("itemCurrent");
????fullcode=gt();
????clearInterval(timer);
????timer?=?setInterval("Truly.load_data_script(AppConf.url+gt(),'vsdata');",?1000);
}
function?stopFresh()
{
????clearInterval(timer);
}
var?jk,zs;
var?currprice,currnum;
var?_A=function(t,c){t.appendChild(c)};
var?fullcode?=?'sh600390';
var?Truly?=?{
????load_data_script:function(url,idname)
????{
????????var?h?=?new?Date().getHours();
????????var?m?=?new?Date().getMinutes();
????????if(h?<?9?||?(h>15)?||?(h?==?15&&?m>10))?stopFresh();
????????var?obj=$(idname);
????????if(obj){obj.parentNode.removeChild(obj);};
????????var?newscript=$C("script");
????????newscript.type="text/javascript";
????????newscript.src=url;
????????newscript.id=idname;
????????_A(document.body,newscript);
????}
}
var?S_Finance={};
S_Finance.upconstants={itemTickettime:null,servertime:null,
setData:function(){
????this.itemTickettime=$("itemTickettime").innerHTML;
????eval("this.hq_str_symbol?=?hq_str_"+fullcode);
????if(this.hq_str_symbol!=null?&&?this.hq_str_symbol!=undefined?&&?this.hq_str_symbol!="undefined"?&&?this.hq_str_symbol!="")
????{
????????this.chgedary=new?Array();
????????this.chgedarylen=0;
????????this.cacheidx=0;
????????this.setValue(this.hq_str_symbol);
????????this.initflag=1;
????}
????else
????{
????????setTimeout(this._updata._Bind(this),AppConf.Interval_AginReq);
????????return?true;
????};
????this.setFlash=function(tid)
????{
????????var?_tidColor=$(tid).style.color;
????????setTimeout(function(){$(tid).style.color="#000000";},400);
????????setTimeout(function(){$(tid).style.color=_tidColor;},600);
????????setTimeout(function(){$(tid).style.color="#000000";},800);
????????setTimeout(function(){$(tid).style.color=_tidColor;},1000);
????};
????if(this.itemTickettime!=$("itemTickettime").innerHTML)
????{
????????$("itemcurrprice").style.fontFamily="Arial";
????????$("itemcurrprice").style.fontSize="11px";
????????$("itemDiffpercent").style.fontFamily="Arial";
????????$("itemDiffpercent").style.fontSize="11px";
????????this.setFlash("itemCurrent");
????????this.setFlash("itemcurrprice");
????????this.setFlash("itemDiffpercent");
????};
????return?true;
},
????setValue:function(data)
????{
????????var?dataContent=data;
????????if(dataContent){
????????????dataContent.replace("\r","");dataContent.replace("\n","");
????????????var?dataArray=dataContent.split(",");
????????????var?arrayLen=dataArray.length;
????????}
????????$("itemTickettime").innerHTML=dataArray[30]+"?"+dataArray[31];
????????$("itemCurrent").innerHTML=dataArray[3];
????????$("name").innerHTML=dataArray[0];
????????$("code").innerHTML=fullcode;
????????currprice?=?(dataArray[3]*1000-dataArray[2]*1000)/1000;
????????currnum=(dataArray[3]*1000-dataArray[2]*1000)/(10*dataArray[2]);
????????$("itemcurrprice").innerHTML=currprice;
????????$("itemDiffpercent").innerHTML=?Math.round(currnum*100)/100?+?'%';
????????jk=dataArray[1];
????????zs=dataArray[2];
????????
????????$("k").innerHTML=jk;
????????$("s").innerHTML=zs;
????????if(dataArray[3]?>zs)?itemCurrent.style.color='#FF0000';
????????else?if(dataArray[3]?==zs)?itemCurrent.style.color='#000000';
????????else?itemCurrent.style.color='#008000';
????????$("itemcurrprice").style.color=itemCurrent.style.color;
????????$("itemDiffpercent").style.color=itemCurrent.style.color;
????}
}
呵呵,寫的很簡單就不往首頁放了。大家慢慢看,玩股票的兄弟們祝你們都賺到錢,不玩股票的就多研究研究技術。這里下載源碼。
enjoy code!
轉載于:https://www.cnblogs.com/Truly/archive/2007/07/31/838157.html
總結
以上是生活随笔為你收集整理的JavaScript随笔一篇的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中国足球十八怪
- 下一篇: ExtJS专题-TreePanel(1)