<div class="codetitle"> <span><a style="CURSOR: pointer" data="28927" class="copybut" id="copybut28927" onclick="doCopy('code28927')"><u>코드 복사</u></a></span> 코드는 다음과 같습니다.</div> <div class="codebody" id="code28927"> <br><html> <br><머리> <br><title>ajax 테스트</title> <br><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <br><script type="text/javascript" src="jquery.js"></script> <br><script type="text/javascript">... <br>function ajaxRequest()...{ <br>var url = $("#stockurl").val() $("# stockinit").val(); <br>$.ajax(...{ <br>url: url, <br>type: 'GET', <br>dataType: 'html', <br>timeout: 2000, <br>success: function( 응답)...{ <br>var stocks = response.split(';') <br>for(var i=0; i<stocks.length-1; i )...{ <BR>var content = 주식[i]; <BR>var temp1 = content.split('=')[0]; <BR>var temp2 = content.split('=')[1] <BR>var code = temp1. substr(temp1.length - 6, 6); <BR>var temp3 = temp2.replace('"', ''); <BR>var name = temp3.split(',')[0]; <BR> var tday_f = temp3.split(',')[1]; <BR>var yest_f = temp3.split(',')[2] <BR>var curr_f = temp3.split(',')[3] ; <BR>var temp_f = curr_f - yest_f <br><br>$('#a' i).html(code) <BR>$('#b' i).html(이름); >if(curr_f > yest_f) ...{ <br>$('#c' i).html("<font color='red'>" curr_f "</font>"); >} else if(curr_f < yest_f) ...{ <BR>$('#c' i).html("<font color='green'>" curr_f "</font>"); <br>} else ...{ <br>$('#c' i).html(curr_f) <br>} <br>$('#d' i).html(tday_f) <br> $('#e' i).html(yest_f); <br>if(temp_f > 0) ...{ <br>$('#f' i).html("<font color='red '>" temp_f.toFixed(2) "</font>"); <br>$('#g' i).html("<font color='red'>" ((temp_f / yest_f) * 100).toFixed(2) "</font> % "); <br>} else if(temp_f < 0) ...{ <BR>$('#f' i).html("<font color='green'>" temp_f.toFixed(2) "< ;/글꼴>"); <br>$('#g' i).html("<font color='green'>" ((temp_f / yest_f) * 100).toFixed(2) "</font> % "); <br>} else ...{ <br>$('#f' i).html(temp_f.toFixed(2)); <br>$('#g' i).html(((temp_f / yest_f) * 100).toFixed(2) " % "); <br>} <br>$('#h' i).html(temp3.split(',')[4]); <br>$('#i' i).html(temp3.split(',')[5]); <br>} <br>} <br>}); <br>} <br><br>$(document).ready(function()...{ <br><br>var stocks = $("#stockinit").val().split(',' ); <br>for(var i=0; i<stocks.length i>addRows() <br>} <br><br>$("#insrow").click (function()...{ <br><br>var stockcd = $("#stockid").val(); <br>if(stockcd == "")...{ <br>alert("股票代号不能为空!"); <br>$("#stockid").focus(); <br>return; <br>} <br>if(stockcd.length != 6)...{ <br>alert("股票代号只能是6位!"); <br>$("#stockid").focus(); <br>return; <br>} <br>var div = 'sh'; <br>if(document.getElementById("sz_id") .checked)...{ div = "sz";} <br>var stocks = $("#stockinit").val() <br>$("#stockinit").val(stocks "," div stockcd); <br>addRows(); <br>}); <br><br>$("#delrow").click(function()...{ <br>var table = document.getElementById(" tableId"); <br>var index = table.rows.length; <br>if (index < 2)...{ <BR>alert("已经没有可删除的行了!"); <BR> } else ...{ <BR>table.deleteRow(index - 1); <BR>var stockvalue = $("#stockinit").val() <BR>var count = stockvalue.split(',') .length; <BR>if(count == 1) ...{ <BR>stockvalue = ""; <BR>} else ...{ <BR>stockvalue = stockvalue.substr(0, stockvalue.length - 9 ); <BR>} <BR>$("#stockinit").val(stockvalue); <BR>} <BR>}) <br><br>window.setInterval("ajaxRequest()",3000) ; <BR>}); <br><br>function addRows()...{ <BR>var table = document.getElementById("tableId") <BR>var index = table.rows.length; >var str=""; <BR>var 행 = 인덱스 <BR>str ='<tr class="tr_cls">' <br>str ='<td align="center"><span id="' "a" 행 '"></span></td>' <br>str ='<td align="center"><span id="' "b" 행 '"></span></td>' <br>str ='<td align="center"><span id="' "c" 행 '"></span></td>' <br>str ='<td align="center"><span id="' "d" 행 '"></span></td>' <br>str ='<td align="center"><span id="' "e" 행 '"></span></td>' <br>str ='<td align="center"><span id="' "f" 행 '"></span></td>' <br>str ='<td align="center"><span id="' "g" 행 '"></span></td>' <br>str ='<td align="center"><span id="' "h" 행 '"></span></td>' <br>str ='<td align="center"><span id="' "i" 행 '"></span></td>' <br>str ='</tr>'; <br>$("#tablebody").append(str) <br>} <br></script> <br><style> . <br>.tr_cls {...}{ <br>높이:30px; <br>글꼴 크기:16px; <br>글꼴-가족:"Times New Roman" <br>배경- color:#FFFFCC <br>} <br></style> <br><body> <br><input type="hidden" ="stockurl" value="http://hq.sinajs.cn/list=" /> <br><input type="hidden" id="stockinit" value="sh000001,sz399001,sh601939,sh600016, sh600528,sh600667,sh601390,sh601857,sz000532,sh600019,sh601111,sh601600,sh601006,sh601333,sh601398,sh601988,sh601328" /> <br><테이블 너비="80 0" 테두리="0" 정렬="가운데" cellpadding="0" cellpacing="0" > <br><tr> <br><td width="115px"> <br>代号:<input type="text" id="stockid" size="6"> <br></td> <br><td width="150px"> <br>区分:上海<input type="radio" name="rad" id=" sh_id" selected>深证<input type="radio" name="rad" id="sz_id"> <br></td> <br><td width="40px"> <input type="button" id="insrow" value="行追加"> <br></td> <br><td width="495px"> <br><input type="button" id="delrow" value="行削除"> <br></td> <br></tr> <br><tr> <br><td colspan="4"> <br><div style="overflow-y:scroll; Overflow-x:auto; 높이:392px; 너비:817px"> <br><table id="tableId" width="800" border="1" align="center" cellpadding="0" cellpacing="0" bordercolor="#000000"> <br><tr bgcolor="#3399FF" height="30px"> <br><thscope="col">股票代号</th> <br><thscope="col">股票명칭</th> <br><thscope="col">当前价格</th> <br><thscope="col">今日开盘</th> <br><thscope="col">昨日收盘</th> <br><thscope="col">当前差价</th> <br><thscope="col">涨跌幅道</th> <br><thscope="col">最高价格</th> <br><thscope="col">最低价格</th> <br></tr> <br><tbody id="tablebody"> <br></tbody> <br></테이블> <br></div> <br></td> <br></tr> <br></테이블> <br></form> <br></body> <br></html><br><br> </td></stocks.length> </div>