javascript - 我用 javascript 创建了一个表格,但表格的内容是在 php.ini 中。如果无法在 js 中运行 php,如何在表格中插入此内容?
问题描述
我用 javascript 创建了一个表格,但表格的内容是在 php.ini 中。如果无法在 js 中运行 php,如何在表格中插入此内容?
<script>
NROW = 10;
body = document.body;
div = document.createElement('div');
body.appendChild(div);
table = document.createElement('table'); table.setAttribute('border','1');
div.appendChild(table);
for(j=0;j<NROW;j++){
tr = document.createElement('tr');
table.appendChild(tr);
td = document.createElement('td');
tr.appendChild(td);
/*HERE IS THE PROBLEM*/
text = createTextNode(<?php echo 'test'?>);
td = document.createElement('td');
tr.appendChild(td);
}
</script>
```fdsklk`
解决方案
只是为了记录和帮助别人。遵循上面 Kinglish 的帮助。
我用这个:
<!DOCTYPE html>
<html>
<body>
<div id="demo">
<h1>The XMLHttpRequest Object</h1>
<button type="button" onclick="loadDoc()">Change Content</button>
</div>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML =
this.responseText;
}
};
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
}
</script>
</body>
</html>
推荐阅读
- asp.net-core - 封闭的泛型类型注册 - Autofac - 无法解析构造函数的参数 x
- ruby-on-rails - Ruby on Rails - 访问当前用户的嵌套属性
- corda - 如何在 Corda 的 Initiator 节点中获取 FlowSession?
- firebase - Firestore:更新对象中的字段会删除先前的字段
- ios - Swift - UISearchBar:EXC_BREAKPOINT(代码=1,子代码=0x10297eabc)
- android - 如何在 Windows 上使用 python 构建 android 应用程序
- git - 使用 remote.repository.push 解析 git push origin
- excel - 排序,将值从表复制到另一个表并计算新值
- python - 如何使用 Python 将 NULL 值插入 PostgreSQL 数据库?
- vba - 将 Word 文档的内容插入电子邮件并使用 VBA 包含默认签名