我有一个占位符,它的名称为{{inactive}}。
{{inactive}} 在我的 HTML 中是一个复选框。
它有 2 个输出,一个输出为“true”,另一个输出为“false”
现在我将替换它,因为当我执行 wkhtmltoPdf.exe 任务时,我的 PDF 中会出现 true 或 false 一词,但我需要:未给出或已给出。
这是一个示例,但它不起作用:
<script>
inact = true;
</script>
<tr style="height:58pt">
<td id="test" align="right">
<script type="text/javascript">
document.write(inact)
</script>
</td>
</tr>
function myFunction() {
var testing;
if (inact = true) {
testing = "are given";
} else {
testing = "not given"; //else = not true (false)
}
document.getElementById("test").innerHTML = testing;
}
最佳答案
- 函数周围缺少脚本标记
- if 语句中的单个等于
- 您没有在任何地方调用该函数
以下是代码的调整版本:
<tr style="height:58pt">
<td id="test" align="right"></td>
</tr>
<script>
inact = true;
function myFunction() {
var testing;
if (inact == true) {
testing = "are given";
} else {
testing = "not given";
}
document.getElementById("test").innerHTML = testing;
}
myFunction();
</script>
关于javascript - 如何替换一个占位符单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25723952/