简体   繁体   English

我可以将div的innerHTML存储到javascript和php中的隐藏文本框中吗

[英]can I store an innerHTML of a div into a hidden text box in javascript and php

I have to store the inner html of a table into a hidden input box. 我必须将表的内部html存储到隐藏的输入框中。 I am able to store it in a JavaScript variable but not been able to store it in the hidden input box. 我能够将其存储在JavaScript变量中,但无法将其存储在隐藏的输入框中。

Here is the code I have written so far: 这是我到目前为止编写的代码:

in .JS file 在.JS文件中

d = document.getElementById('address').innerHTML;
document.getElementById('hid1').value = d;

in .php file 在.php文件中

<input type="hidden" id="hid1" name="hid1"/>

Please help me with this...am really clueless on what to do 请帮我解决这个问题。。。我真的不知所措

If I am not mistaken, the way you have it set up currently, you will need to append the value attribute to the <input> before assigning a value to that element's value property. 如果我没有记错的话,请按照当前的设置方式,将value属性附加到<input> 然后再为该元素的value属性分配一个值。

If you include the value attribute in your HTML from the start, like this: 如果从一开始就在HTML包含value属性,则如下所示:

<input type="hidden" id="hid1" name="hid1" value="" />

your javascript should work exactly as you intend. 您的javascript应该可以完全按照您的预期工作。

here is an implementation, the textfield isn't hidden (for obvious reasons).. but hiding it shouldn't be a problem. 这是一个实现,不会隐藏文本字段(出于明显的原因)..但是隐藏它应该不是问题。

var data = document.getElementById('someDiv').innerHTML;
document.getElementById('hiddenField').value = data;

this should do (ensure the id hiddenField is unique in the document or hid1 in your case) 这应该做(确保id hiddenField在文档中是唯一的,或者在您的情况下为hid1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 div 框中显示来自 javascript innerhtml 的文本输出,而不会出现文本溢出和 html/css 样式 - How can I show a text-output from javascript innerhtml in a div-box without the text overflowing and with html/css styling 我无法通过使用 val() 或 innerHTML 或 - I can not get text value in a div by using val() or innerHTML or 如何获取被javascript覆盖的文本的innerHTML - How can I get the innerHTML of a text that is overwritten with javascript 如何通过单击隐藏在 JavaScript 中的 div 来触发函数? - How can I trigger a function by clicking a div which is hidden in JavaScript? 无法在javascript滑动div中设置文本框值 - Can't set text box value inside javascript sliding div Javascript不带隐藏文本框值吗? - Javascript does not take hidden text box value? 如何从具有2个文本框的jQuery对话框中获取值? 我可以将它们存储在JavaScript变量中吗? - How can I get values from jQuery dialog box which has 2 text boxes? Can I store them in a JavaScript variable? 如何存储文本框值供以后与Javascript一起使用? - How do I store text box values for later use with Javascript? 我可以使用 css 为 div 的 innerHTML 设置动画吗? - Can I animate innerHTML of a div using css? 使用JavaScript使框变大,然后使用函数和InnerHTML在其中显示文本 - Making a box grow with JavaScript, then text appearing inside, using a function and InnerHTML
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM