我试图将文本文件放入textarea.结果是" http://mywebsite.com/textfile/(txtinput).txt,文本文件未加载到textarea中.
<html>
<head>
<title>textbox</title>
<script type="text/javascript">
function readBOX() {
var txtinput = document.getElementById('txtinput').value;
document.forms[0].text.value = ("http://mywebsite.com/textfile/") + txtinput +(".txt");
}
</script>
</head>
<body>
<p> Type</p>
<input type="text" id="txtinput" />
<input id="open" type="button" value="READ" onClick="readBOX()" />
<form>
<textarea name="text" rows="20" cols="70">loaded text here</textarea>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
Mar*_*tin 12
您必须使用本答案中公布的内容
$(document).ready(function() {
$("#open").click(function() {
$.ajax({
url : "helloworld.txt",
dataType: "text",
success : function (data) {
$("#text").text(data);
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
我不想使用jQuery你必须使用XMLHttpRequest-Object之类的东西:
var xmlhttp, text;
xmlhttp = new XMLHttpRequest();
xmlhttp.open('GET', 'http://www.example.com/file.txt', false);
xmlhttp.send();
text = xmlhttp.responseText;
Run Code Online (Sandbox Code Playgroud)
但这可以在这里的SO-Answer 或维基百科上完整且可理解的文档中阅读
注意:但这不是跨浏览器兼容的,对于较旧的IE版本,您必须使用该ActiveXObject("Microsoft.XMLHTTP")对象
感谢大家。JavaScript 不适合我。我改用PHP,它运行得很好。
<!DOCTYPE HTML>
<html>
<head>
<title>textbox</title>
</head>
<body>
<form action="process.php" method="post">
<input type="text" name="name" />
<input type="submit" />
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
进程.php
<textarea name="text" rows="20" cols="70">
<?php $name = $_POST["name"]; echo file_get_contents("$name");?>
</textarea>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
39140 次 |
| 最近记录: |