gpt4 book ai didi

javascript - 如何在不点击提交按钮的情况下显示值(value)

转载 作者:行者123 更新时间:2023-11-30 17:57:54 28 4
gpt4 key购买 nike

我正在使用 html5 和 javascript。我正在从 java 脚本读取 excel 文件并显示输出。请先分析我的代码

 <input type="button" id="btnSubmit" onclick="readdata(1, 2)" value="Submit" />

var xVal = 1;
var yVal = 2

function readdata(x,y) {
x = xVal;
y = yVal;
try {
var excel = new ActiveXObject("Excel.Application");
excel.Visible = false;
var excel_file = excel.Workbooks.Open("D:\\Test.xls");// alert(excel_file.worksheets.count);
var excel_sheet = excel_file.Worksheets("Sheet1");
var data = excel_sheet.Cells(x, y).Value;
//alert(data);
drawWithexcelValue(data);
xVal = xVal + 1;
}
catch (ex) {
alert(ex);
}

现在我从这段代码读取文件并用这段代码显示输出:

function drawWithexcelValue(val) {

var txtSpeed = val; //alert(txtSpeed.value);
if (txtSpeed !== null) {

iTargetSpeed = txtSpeed;

// Sanity checks
if (isNaN(iTargetSpeed)) {
iTargetSpeed = 0;
} else if (iTargetSpeed < 0) {
iTargetSpeed = 0;
} else if (iTargetSpeed > 80) {
iTargetSpeed = 80;
}

job = setTimeout("draw()", 5);
}
}

Q .1 每次我单击提交按钮时,它都会显示 excel 文件中的值,我希望我不必每次都单击提交按钮..它会在某个时间间隔自动显示值说 4 秒。

Q :-2 我不想要提交按钮,这意味着当我运行这段代码时它会自动开始运行脚本说 onload ="readdata(1, 2)",但它只显示一个值.. .如何以一定的时间间隔显示所有值..请帮助!!!!

伙计们,如果你能给我编辑过的代码,那对我来说真的很有帮助

最佳答案

这段代码肯定对你有用

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Speedometer HTML5 Canvas</title>

<script src="script copy.js">

</script>

</head>
<body onload='draw(0);'>
<canvas id="tutorial" width="440" height="220">
Canvas not available.
</canvas>
<div id="divHidden" style="visibility: hidden; width: 0px; height: 0px">
<form id="drawTemp">
<input type="text" id="txtSpeed" name="txtSpeed" value="20" maxlength="2" />
<input type="button" value="Draw" onclick="drawWithInputValue();">
<input type="file" id="file" onchange="checkfile(this);" />
<input type="button" id="btnSubmit" onclick="readdata(1, 2)" value="Submit" />


<button onclick="myStopFunction()">Stop Meter</button>


</form>
</div>
</body>
</html>

<script type="text/javascript" language="javascript">


var myVar=setInterval(function(){readdata(1,2)},2000);
function myStopFunction()
{
clearInterval(myVar);
}


function checkfile(sender) {
var validExts = new Array(".xlsx", ".xls", ".csv");
var fileExt = sender.value;
fileExt = fileExt.substring(fileExt.lastIndexOf('.'));
if (validExts.indexOf(fileExt) < 0) {
alert("Invalid file selected, valid files are of " +
validExts.toString() + " types.");
return false;
}
else return true;

}
var xVal = 1;
var yVal = 2

function readdata(x,y) {
x = xVal;
y = yVal;
try {
var excel = new ActiveXObject("Excel.Application");
excel.Visible = false;
var excel_file = excel.Workbooks.Open("D:\\Test.xls");// alert(excel_file.worksheets.count);
var excel_sheet = excel_file.Worksheets("Sheet1");
var data = excel_sheet.Cells(x, y).Value;
//alert(data);
drawWithexcelValue(data);
xVal = xVal + 1;
if(data==null || data=="")
{
myStopFunction();
}
excel.Application.Quit();
}
catch (ex) {
alert(ex);
}
}
</script>

关于javascript - 如何在不点击提交按钮的情况下显示值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17749718/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com