如何将html中的span值传递给其他页面 [英] How to pass the value of span in html to other page
问题描述
我想传递我的span html的值,这是值,来自javascript。它将计算上传文件的字数。请帮帮我们。
I want to pass the value of my span html which is the value, is from the javascript. It will count the words of the uploaded file. please help me guys for this.
继承我的第一页 index.php
<form name="myform" action="values.php" method="post">
<input name="upload" type="file" id="upload" accept="text/plain" accesskey="u"> UPLOAD A FILE
<span id="display_File_count" name="display_File_count"></span> <span>Words</span>
<input type="submit" value="Submit">
</form>
<script type="text/javascript">
$('#upload').change( function(event) {
var f = event.target.files[0];
if (f) {
var r = new FileReader();
r.onload = function(e) {
var contents = e.target.result;
var res = contents.split(" ");
$("#display_File_count").text(res.length);
}
r.readAsText(f);
}
});
</script>
还有另一个会调用值 values.php <的页面/ p>
And heres the other page that will call the value values.php
<input type="text" name="count_upload" id="count_upload" value="<?php echo $_POST["display_File_count"] ?>" >
推荐答案
你可以添加一个包含文件的隐藏输入count(从js更新)和提交按钮将数据发送到另一页:
You could add an hidden input that will contain the file count (updated from js) and submit button to send data to the other page :
<form name="myform" action="values.php" method="post">
<input name="upload" type="file" id="upload" accept="text/plain" accesskey="u">
UPLOAD A FILE
<span id="display_File_count" name="display_File_count"></span><span>Words</span>
<input type="hidden" name="display_File_count" class='display_File_count' />
<input type='submit' value='send data to the other page' />
</form>
要从js更新字段,您可以使用:
To update field from js you could use :
...
r.onload = function(e) {
var contents = e.target.result;
var res = contents.split(" ");
$("#display_File_count").text(res.length);
$(".display_File_count").val(res.length);
}
...
当您点击提交按钮时参数 display_File_count
将自动发送到 values.php
,方法为 post
,所以你应该在 values.php
中找到由 display_File_count
自动填充的输入,因为你正在使用 $ _ POST [display_File_count]
在另一边。
When you click on submit button the parameter display_File_count
will be send automatically to values.php
with method post
, so you should find in values.php
the input filled automatically by display_File_count
since you're using $_POST["display_File_count"]
in the other side.
希望这有帮助。
这篇关于如何将html中的span值传递给其他页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!