如何替换一个占位符单词

How can I replace one Placeholder Word?

本文关键字:一个 占位符 单词 替换 何替换      更新时间:2023-09-26

我有一个占位符,它被命名为{{inactive}}

{{inactive}}在我的HTML中是一个复选框。

它有两个输出,一个输出为"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>

你必须像下面这样做:

您的HTML应该是:

<script>
 inact = false;
</script>
<body onload="myFunction();">
<table>
<tr style="height:58pt">
  <td id="test" align="right">
    <script type="text/javascript">
        document.write(inact)
    </script>
</td>
</tr>
</table>    
</body>

你的JS应该是:

function myFunction() {
var testing;
if (inact == true) {
    testing = "are given";
} else {
    testing = "not given"; //else = not true (false) 
}
document.getElementById("test").innerHTML = testing;
}

现在你会得到正确的结果。