我有 JS 文件:
var text1 = "There is text1";
var text2 = "There is text2";
var text3 = "There is text3";
Run Code Online (Sandbox Code Playgroud)
在变量 actual_text 中,我在 str 中有“text2”。
actual_text = "text2";
Run Code Online (Sandbox Code Playgroud)
它是字符串,因为它基于前面的代码,这是正确的。
现在我需要将 actual_text 中的“text2”重新输入到 text2(作为带有内容的变量)并使用变量 actual_text 将其输出:
<p id="myoutput"></p>
document.getElementById('myoutput').innerHTML=actual_text;
Run Code Online (Sandbox Code Playgroud)
尝试这个:
var text1 = "There is text1";
var text2 = "There is text2";
var text3 = "There is text3";
actual_text = "text2";
document.getElementById('myoutput').innerHTML = this[actual_text];Run Code Online (Sandbox Code Playgroud)
<p id="myoutput"></p>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
79 次 |
| 最近记录: |