ajax无刷新动态调用股票信息(改良版)
配资开户
汇盈盘配资牛金所股票配资亚晶配资配资微信群
股票
2020-07-31

ajax test

...

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

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).html(code);

$('#b'+i).html(name);

if(curr_f > yest_f) ...{

$('#c'+i).html("" + curr_f + "");

} else if(curr_f < yest_f) ...{

$('#c'+i).html("" + curr_f + "");

} else ...{

$('#c'+i).html(curr_f);

}

$('#d'+i).html(tday_f);

$('#e'+i).html(yest_f);

if(temp_f > 0) ...{

$('#f'+i).html("" + temp_f.toFixed(2) + "");

$('#g'+i).html("" + ((temp_f / yest_f) * 100).toFixed(2) + " % ");

} else if(temp_f < 0) ...{

$('#f'+i).html("" + temp_f.toFixed(2) + "");

$('#g'+i).html("" + ((temp_f / yest_f) * 100).toFixed(2) + " % ");

} else ...{

$('#f'+i).html(temp_f.toFixed(2));

$('#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

addRows();

}

$("#insrow").click(function()...{

var stockcd = $("#stockid").val();

if(stockcd == "")...{

alert("股票代号不能为空!");

$("#stockid").focus();

return;

}

if(stockcd.length != 6)...{

alert("股票代号只能是6位!");

$("#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("已经没有可删除的行了!");

} 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);

}

});

window.setInterval("ajaxRequest()",3000);

});

function addRows()...{

var table = document.getElementById("tableId");

var index = table.rows.length;

var str="";

var row = index - 1;

str+=''

str+=''

str+=''

str+=''

str+=''

str+=''

str+=''

str+=''

str+=''

str+=''

str+='';

$("#tablebody").append(str);

}

...

.tr_cls {...}{

height:30px;

font-size:16px;

font-family:"Times New Roman", Times, serif;

background-color:#FFFFCC

}

代号:

区分:上海深证

股票代号

股票名称

当前价格

今日开盘

昨日收盘

当前差价

涨跌幅度

最高价格

最低价格