我运行代码后如何保留我的浏览器页面值 [英] How To Retain My Browser Page Values After I Have Run The Code

查看:86
本文介绍了我运行代码后如何保留我的浏览器页面值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用html的java脚本代码。

i希望每当我在浏览器中运行我的代码时,我希望浏览器显示之前的值而不是空白t填充值。

怎么做PLZ帮助。

提前预付款。



<!DOCTYPE html>

< html>

< head>



< title>生成预算< / title>

< / head>

< script type =text / javascript>



函数tableprint()

{



var numOfYears = Math.abs(document.getElementById('end')。value -



document.getElementById('start')。value);

var budget = Math.abs(document.getElementById('budget')。value);

var i = 0;



var tableHtml =;









for(i = 0; i< = numOfYears; i ++)

{tableHtml = tableHtml.concat(();

tableHtml = tableHtml.concat(Number(document.getElementById



('start') .value)+ Number(i));

tableHtml = tableHtml.concat(:);

tableHtml = tableHtml.concat(Budget);

tableHtml = tableHtml.concat(:);

tableHtml = tableHtml.concat(budget / numOfYears);

tableHtml = tableHtml.concat( ;);

tableHtml = tableHtml.concat(预测);

tableHtml = tableHtml.concat(:);

tableHtml = tableHtml.concat(Number(document.getElementById('for'+ i).value));

tableHtml = tableHtml.concat(;);

tableHtml = tableHtml.concat(Actual);

tableHtml = tableHtml.concat(:);

tableHtml = tableHtml.concat(Number(document.getElementById) ('act'+ i).value));

tableHtml = tableHtml.concat());



}

documen t.getElementById(form2)。innerHTML = tableHtml;

}





函数generateBudget()

{var numOfYears = Math.abs(document.getElementById('end')。value -



document.getElementById('start' ).value);

localStorage.setItem(Math.abs(document.getElementById('end')。value -



文件.getElementById('start')。value),numOfYears);

var budget = Math.abs(document.getElementById('budget')。value);

localStorage.setItem(Math.abs(document.getElementById('budget')。value),预算)

var i = 0;



if(numOfYears< 1)

{

numOfYears = 1;

}



var tableHtml =;

tableHtml = tableHtml.concat();

for(i = 0; i< = numOfYears; i ++)

{

tableHtml = tableHtml.concat();

}

tableHtml = tableHtml.concat();

tableHtml = tableHtml.concat();



for(i = 0; i< = numOfYears; i ++)

{

tableHtml = tableHtml.concat();

}



tableHtml = tableHtml。 concat();

tableHtml = tableHtml.concat();



for(i = 0; i< = numOfYears ; i ++)

{

tableHtml = tableHtml.concat();

}



tableHtml = tableHtml.concat();

tableHtml = tableHtml.concat();



for (i = 0; i< = numOfYears; i ++)

{

tableHtml = tableHtml.concat();

}

tableHtml = tableHtml.concat(

);

tableHtml = tableHtml.concat(Number(document.getElementById



('start')。value)+ Number(i));

tableHtml = tableHtml.concat(
预算 );

tableHtml = tableHtml.concat(budget / numOfYears);

tableHtml = tableHtml。 concat(
Forecast );

tableHtml = tableHtml.concat(< input type ='text 'name ='代表+ Number(i)+'



id ='for+ Number(i)+'/>);

tableHtml = tableHtml.concat(
Actual );

tableHtml = tableHtml .concat(< input type ='text'name ='act+ Number(i)+'



id ='act+ Number(i )+'/>);

tableHtml = tableHtml.concat(
);

tableHtml = tableHtml.concat(
< input type ='button'name ='su bmit'



id ='submit'value ='Submit'/>
);



document.getElementById(form)。innerHTML = tableHtml;





}



< / script>



Start Year < input type =textname =startid =start/>

End Year


< input type =textname =endid =end/>

预算 < input type =textname =预算id =预算/>

< input type =buttonname =generateid =generatevalue = 生成



/>




i have java script code using html.
i want that whenever i run my code in browser i want the browser to display the previous values and not blank t fill values again.
how to do plz help.
thanx in advance.

<!DOCTYPE html>
<html>
<head>

<title>Generate Budget</title>
</head>
<script type="text/javascript">

function tableprint()
{

var numOfYears = Math.abs(document.getElementById('end').value -

document.getElementById('start').value);
var budget = Math.abs(document.getElementById('budget').value);
var i = 0;

var tableHtml = "";




for (i=0; i<=numOfYears; i++)
{tableHtml = tableHtml.concat("(");
tableHtml = tableHtml.concat(Number(document.getElementById

('start').value)+Number(i));
tableHtml = tableHtml.concat(":");
tableHtml = tableHtml.concat("Budget");
tableHtml = tableHtml.concat(":");
tableHtml = tableHtml.concat(budget/numOfYears);
tableHtml = tableHtml.concat(";");
tableHtml = tableHtml.concat("Forecast");
tableHtml = tableHtml.concat(":");
tableHtml = tableHtml.concat(Number(document.getElementById('for'+i).value));
tableHtml = tableHtml.concat(";");
tableHtml = tableHtml.concat("Actual");
tableHtml = tableHtml.concat(":");
tableHtml = tableHtml.concat(Number(document.getElementById('act'+i).value));
tableHtml = tableHtml.concat(")");

}
document.getElementById("form2").innerHTML =tableHtml;
}


function generateBudget()
{ var numOfYears = Math.abs(document.getElementById('end').value -

document.getElementById('start').value);
localStorage.setItem("Math.abs(document.getElementById('end').value -

document.getElementById('start').value)", numOfYears);
var budget = Math.abs(document.getElementById('budget').value);
localStorage.setItem("Math.abs(document.getElementById('budget').value)",budget)
var i = 0;

if( numOfYears < 1)
{
numOfYears = 1;
}

var tableHtml = "";
tableHtml = tableHtml.concat("");
for (i=0; i<=numOfYears; i++)
{
tableHtml = tableHtml.concat("");
}
tableHtml = tableHtml.concat("");
tableHtml = tableHtml.concat("");

for (i=0; i<=numOfYears; i++)
{
tableHtml = tableHtml.concat("");
}

tableHtml = tableHtml.concat("");
tableHtml = tableHtml.concat("");

for (i=0; i<=numOfYears; i++)
{
tableHtml = tableHtml.concat("");
}

tableHtml = tableHtml.concat("");
tableHtml = tableHtml.concat("");

for (i=0; i<=numOfYears; i++)
{
tableHtml = tableHtml.concat("");
}
tableHtml = tableHtml.concat("

");
tableHtml = tableHtml.concat(Number(document.getElementById

('start').value)+Number(i));
tableHtml = tableHtml.concat("
Budget");
tableHtml = tableHtml.concat(budget/numOfYears);
tableHtml = tableHtml.concat("
Forecast");
tableHtml = tableHtml.concat("<input type='text' name='for" +Number(i)+"'

id='for" + Number(i) + "' />");
tableHtml = tableHtml.concat("
Actual");
tableHtml = tableHtml.concat("<input type='text' name='act" +Number(i)+"'

id='act" + Number(i) + "' />");
tableHtml = tableHtml.concat("
");
tableHtml = tableHtml.concat("
<input type='button' name='submit'

id='submit' value='Submit' />
");

document.getElementById("form").innerHTML = tableHtml;


}

</script>

Start Year <input type="text" name="start" id="start" />
End Year

<input type="text" name="end" id="end" />
Budget <input type="text" name="budget" id="budget" />
<input type="button" name="generate" id="generate" value="Generate"

/>




< textarea id = form2>

< / textarea>

< / body>

< / html>

这是代码


<textarea id="form2">
</textarea>
</body>
</html>
this is the code

推荐答案

你问的问题来自同一点:你将在哪里存储浏览器会话之间的数据。



关于评论员建议的cookie - 除非,如果浏览器设置像我的,它将在关闭时删除它们。此外,如果其他用户打开浏览器该怎么办:他们应该看到最后一个用户的最后一个值还是他们自己的最后一个值 - >如果他们在同一台机器上切换浏览器会发生什么?



您需要一个尽可能不受用户浏览器和设置限制的存储区域。这确实需要您将数据存储在服务器端而不是客户端。然后,您可以将数据存储在数据库或文件,服务器端,并且上一段中的所有问题都会消失。



我建议php [了解这里的方法]



如果这是用户特定的,你需要一些方法来知道哪个用户正在请求数据。



至于你能不能给我代码 - 我把它留给你。
The question you ask comes down to the same point: where will you store the data between browser sessions.

On commentator suggested cookies - that would work except, if the browser's set up like mine, it will delete them when it is closed. Also, what if a different user opens the browser: should they see the last values of the last user or their own last values -> and what happens if they switch browsers on the same machine?

You need a storage area that is not at the mercy, so far as possible, of the user's browser and settings. This really, then, requires you store the data on the server side instead of the client side. You could then store the data in a database or file, server side, and all of the problems in the previous paragraph go away.

I suggest php [Learn how here]

If this is to be user specific, you'll need some way to know which user is requesting the data.

As for "can you plz give me the code" - I leave that to you.


这篇关于我运行代码后如何保留我的浏览器页面值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆