如何获取包含值的输入控件的innerHTML? [英] How to get the innerHTML of an input control including the values?

查看:123
本文介绍了如何获取包含值的输入控件的innerHTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div,它叫做tab1。在tab1 div中有许多输入(字段和单选按钮)。我得到了像这样的innerHTML:

I have a div, its called tab1. Inside the tab1 div are many inputs (fields and radio buttons). I am getting the innerHTML like this:

document.getElementById("tab1").innerHTML;

示例代码:

<div id="tab1">
    <input type="text" id="text1" />
</div>

这是有效的,但是如果我在text1输入中输入任何值,例如,它不在innerHTML中。我如何获得包含输入值的innerHTML?这有可能吗?

That works, but if I entered any value into a text1 input for example, its not in the innerHTML. How would I get the innerHTML including the entered values? Is that possible at all?

谢谢!

推荐答案

<div id="tab1">
    <input type="text" id="text1"
    onkeyup="javascript:this.setAttribute("value", this.value);"/>
</div>

这将给出div的innerHTML值。

This will gives the values with div's innerHTML.

document.getElementById("tab1").innerHTML;

您可以相应地更改事件,我将其设置为 onKeyUp

You can change the event accordingly, I set it onKeyUp.

这篇关于如何获取包含值的输入控件的innerHTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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