我正在设定目标,并显示您的进度,我使用progress元素。我想用php / js / other将我的目标保存到我的服务器上名为user.txt的.txt文件中。我已经尝试了这个Write server text files with Ajax和PHP write file from input to txt显示了我想要的内容,但我只需要2个输入字段而不是表单标记 有什么方法可以合并这两个文件,将我的数据从我的2个字段保存到文本文件(user.txt) 这是我的代码:
function myFunction() {
var x = document.getElementById("myTextarea").value;
document.getElementById("myProgress").value = x;
}
function myFunction2() {
var x = document.getElementById("myTextarea2").value;
document.getElementById("myProgress").max = x;
}

progress {
color: #0063a6;
font-size: .6em;
line-height: 1.5em;
text-indent: .5em;
width: 30em;
height: 3em;
border: 1px solid #0063a6;
background: #fff;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<h3>Goal Progress:</h3>
<progress id="myProgress" value="0" max="100">
</progress>
<hr>
<input type="text" id="myTextarea"></input>
<button onclick="myFunction()">Add</button>
<hr>
<input type="text" id="myTextarea2" />
<button onclick="myFunction2()">Set Goal</button>
<hr>
&#13;
答案 0 :(得分:0)
在这里,我终于解决了我困惑的范式:
<html>
<body onload="timer=setTimeout('myFunction2(); myFunction();',3000)">
<style>
progress {
color: #0063a6;
font-size: .6em;
line-height: 1.5em;
text-indent: .5em;
width: 30em;
height: 3em;
border: 1px solid #0063a6;
background: #fff;
}
</style>
<h3>Goal Progress:</h3>
<progress id="myProgress" value="0" max="100">
</progress>
<hr>
<form action="form.php" method="POST">
add money:
<input type ="text" name="field1" id="myTextarea"></input>
<hr>
Goal:
<input type ="text" name="field2" id="myTextarea2"/>
<input type="submit" name="submit" value="Save Data">
</form>
<hr>
<button onclick="myFunction2(); myFunction();">show new progress</button>
<script>
function myFunction() {
var x = document.getElementById("myTextarea").value;
document.getElementById("myProgress").value = x;
}
function myFunction2() {
var x = document.getElementById("myTextarea2").value;
document.getElementById("myProgress").max = x;
}
</script>
</body>
</html>
&#13;