如何在html中打印或显示JS变量 [英] How do I print or display JS variables in html

查看:2449
本文介绍了如何在html中打印或显示JS变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

For some reason clicking the button will not but the variable in the textbox, I'm not getting any syntax errors in my compiler so I think it's a logic error. THanks in advance

JS:

    var testvar = 5
    $('.teambtn').click(function() {
    document.getElementById('team').text = (testvar);
    });

html:

    <textarea id=team cols="50" rows="10">
    Your Team Will be here:
    </textarea>


                <button type="button" id=teambtn class="btn">Export</button>

推荐答案

('.teambtn')。click(function(){
document.getElementById('team')。text =(testvar);
});

html:

< textarea < span class =code-attribute> id = 团队 cols = 50 = 10 >
您的团队将在这里:
< / textarea >


< 按钮 type = 按钮 id = < span class =code-keyword> teambtn class = btn > 导出< / button >
('.teambtn').click(function() { document.getElementById('team').text = (testvar); }); html: <textarea id=team cols="50" rows="10"> Your Team Will be here: </textarea> <button type="button" id=teambtn class="btn">Export</button>


<pre><script>

  document.getElementById('your id of textbox').value = your_variable_js;

</script></pre>

this?


运行此示例并弄明白:

Run this example and figure it out:
<!DOCTYPE html>
<html>
<body>
<p id="para1"></p>
<input type="text" id="textbox1" value="">
<script>
var js_variable = "Got it?";
document.getElementById("para1").innerHTML = js_variable;
document.getElementById("textbox1").value = js_variable;
</script>
</body>
</html>


这篇关于如何在html中打印或显示JS变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆