var data1=0,data2=0,result=0
function read(){
//读取1.txt
$.ajax({
url : "1.txt",
cache : false,
success : function(data,status){
data1=data
}
})
//读取2.txt
$.ajax({
url : "2.txt",
cache : false,
success : function(data,status){
data2=data
compute()//计算
}
})
}
function compute(){
var r=0
while(data1!=0){
r=data1-data2*2
若计算结果有变化,将结果放在div中,也可以放在数据库中
if(result!=r){
$("#div3").append(r)
$("#div3").append('<br>')
result=r
}
break
}
}
$(document).ready(function(){
read()
setInterval("read()",3000)//定时循环读取
})
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form>
<table class="table table-striped">
<caption>用户注册</caption>
<tbody>
<tr class="title">
<td colspan="2">登录信息填写:以下请填写登录信息</td>
</tr>
<tr>
<td id="a2" class="title">用 户 名<br /><span>长度限制8个字符或汉字</span></td>
<td id="b2"><input type="text" name="username" id="uname"> <span>(必填项目)(建议使用真实姓名注册)</span></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="2"><input type="submit" value=" 提 交 " onClick="submit()"><input type="submit" value=" 重 置 "></td>
</tr>
</tfoot>
</table>
</form>
<script type="text/javascript">
/**
* 获取地址栏参数
* @param key 参数名
*/
var getParam = function (key) {
var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)")
var r = window.location.search.substring(1).match(reg)
return r ? decodeURI(r[2]) : null
}
var username = getParam('username')
if (username) {
document.getElementById("b2").innerHTML = username
}
</script>
</body>
</html>