[英]Display span tag value in a textfiled
I am displaying a value using span tags; 我正在使用span标签显示值;
JS JS
<script>
window.onload = function () {
document.getElementById('tag').innerHTML = 122;
};
</script>
HTML HTML
<div id="tag"></div>
The value 122
gets displayed on the screen. 值122
显示在屏幕上。 But what i want is to display the value 122
in a text filed
. 但我想要的是在text filed
字段中显示值122
。 How can i do this ? 我怎样才能做到这一点 ?
Change your html to: 将您的HTML更改为:
<input type="text" id="tag">
And your js to: 你的js:
window.onload = function () {
document.getElementById('tag').value = 122;
};
You can simply add an input to the DOM as <input type="text" id="tag">
and keep your 您只需将输入添加到DOM作为<input type="text" id="tag">
并保留您的
javascript as window.onload = function () {
document.getElementById('tag').value = 122;
};
This will do the job for you. 这将为您完成这项工作。
OR Keeping your code same , you can do it as below: 或者保持代码相同,您可以按照以下方式执行:
HTML: HTML:
<div id="tag"></div>
JS: JS:
<script type="text/javascript">
window.onload = function(){
// create a textfield dynamically, say it is "text"
document.getElementById('tag').appendChild(text);
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.