当前位置: 网学 > 编程文档 > Ajax > 正文

使用ajax技术无刷新动态调用股票信息

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/07/10
ext/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(''='');
var code = temp1.substr(temp1.length - 6, 6);
var temp3 = temp2.replace(''"'', '''');
var name = temp3.split('','')[0];
var tday_f = temp3.split('','');
var yest_f = temp3.split('','');
var curr_f = temp3.split('','');
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) * 100).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) * 100).toFixed(2) + "</font> %";
} else ...{
$(''f''+i).innerHTML = temp_f.toFixed(2);
$(''g''+i).innerHTML = ((temp_f / yest_f) * 100).toFixed(2) + " % ";
}
$(''h''+i).innerHTML = temp3.split('','');
$(''i''+i).innerHTML = temp3.split('','');
}
}
function pageInit() ...{
window.setInterval("ajaxRequest()",3000);
}
</script>

当然页面部分完全可以由脚本自动生成,以及页面动态增减股票信息等功能,就等日后修改吧。

网学推荐

免费论文

原创论文

设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号