如何在重新加载/刷新网站时运行javascript函数(数学计算)?有没有一种简单的方法可以做到这一点?
以下简单计算的结果应该在。)网站刷新时刷新,b。)当任何数学值发生变化时。
我已经尝试过onload而不是onclick,但这并没有改变任何东西。
我建立了一个实时网站,请看这里:
http://90.153.112.5:8888/djdp42Bjjr39399nfjjj39xleit832991vnJ39921/live/test.php
和代码(test.php):
<?php
require_once("dbcontroller.php");
$db_handle = new DBController();
$sql = "SELECT * from strategy_sheets";
$faq = $db_handle->runQuery($sql);
?>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script>
function showEdit(editableObj) {
$(editableObj);
}
function saveToDatabase(editableObj,column,id) {
$(editableObj);
$.ajax({
url: "saveedit.php",
type: "POST",
data:'column='+column+'&editval='+editableObj.innerHTML+'&id='+id,
success: function(data){
$(editableObj);
}
});
}
</script>
</head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style>}
</style>
<body>
<table class="tbl-qa">
<tr>
<td >DESCRIPTION:</td>
<?php
foreach($faq as $k=>$v) {
?>
<td contenteditable="true" id="Event" onBlur="saveToDatabase(this,'event','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["event"]; ?></td>
<?php
}
?>
</table>
<hr>
<table class="tbl-qa">
<tr>
<td>VALUE 1:</td>
<?php
foreach($faq as $k=>$v) {
?>
<td contenteditable="true" id="Tank" size="2" oninput="output();output2();output3();" onBlur="saveToDatabase(this,'Tank','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["Tank"]; ?></td>
<?php
}
?>
<td>VALUE 2:</td>
<?php
foreach($faq as $k=>$v) {
?>
<td contenteditable="true" id="Spritverbrauch" size="2" oninput="output();output3();" onBlur="saveToDatabase(this,'Spritverbrauch','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["Spritverbrauch"]; ?></td>
<?php
}
?>
</tr>
<tr>
<p></p>
<td>RESULT: </td>
<td><a id="StintlangeRd" onload="output();output3();"></td>
</tr>
</table>
<script type="text/javascript">
function output(){
var value2 = document.getElementById('Tank').textContent;
var value3 = document.getElementById('Spritverbrauch').textContent;
document.getElementById('StintlangeRd').innerHTML = (parseFloat(value2) / parseFloat(value3)).toFixed(2);
}
</script>
<script type="text/javascript">
setTimeout(function(){
location.reload();
},60000);
</script>
</body>
</html>