内部HTML问题
如何获取文本框的值以及 innerHTML
?
例如,如果我有,
<html>
<head>
</head>
<body>
<div id="getvalue">
<p><input type="text" name="username" id="username"></p>
</div>
</body>
</html>
我需要特定 id="getvalue"
的 innerHTML
以及文本框值。如果我使用我得到了结果
var gotvalue=document.getElementBYId('getvalue').innerHTML;
我刚刚得到了结果
"<p><input type="text" name="username" id="username"></p>"
另外,我需要文本框值以及innerHTML
。我怎么能这样做呢?
提前致谢。
How do I get the values of textboxe's along with innerHTML
?
For example, if I have
<html>
<head>
</head>
<body>
<div id="getvalue">
<p><input type="text" name="username" id="username"></p>
</div>
</body>
</html>
I need the innerHTML
of the particlular id="getvalue"
along with the textbox value. I got the result if i use
var gotvalue=document.getElementBYId('getvalue').innerHTML;
I just got the result
"<p><input type="text" name="username" id="username"></p>"
Also, I need the textbox value along with the innerHTML
. How could i do this?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要
的
元素,如下所示:.value
属性 >You want the
.value
property of the<input>
element, like this:由于我只能想象出一个半途而废的理由来说明您需要innerHTML(将其放在文档中的其他位置进行复制),因此我建议使用DOM方法来获取副本:
cloneNode(true) 并使用 DOM 方法(哪一个取决于放置位置)将其注入到 DOM 中。
cloneNode() 也会保留属性,因此值也会被复制。
如果您确实需要该字符串,请忘记这个^^
As i can only imagine one halfway good reason for what you need the innerHTML(put it somewhere else into the document for copying), I would suggest to use the DOM-method to get the copy:
cloneNode(true)
and also use a DOM-Method(which one depends on where to put) to inject it into the DOM.cloneNode() will preserve the attributes too, so the value will also be copied.
If you really need the string, forget this ^^