将 td 元素的 HTML 设置为隐藏字段的值

发布于 2024-09-15 10:42:43 字数 468 浏览 4 评论 0原文

我想知道如何将 td 元素的 HTML 设置为隐藏字段的值。

<td align="center">
       <%if (inst_dm != null) {%>

    ...some code..
</td>
  <%} else {%>

<td align="center"> Contact not available.
   <%}%>
  <input type="hidden" name="inst_dmhidden" value="<%$(this).html().trim(); %>">

</td>

所以,我基本上想要的是,在输入字段 inst_dmhidden 中,来自(..some code..)部分的值或“联系人不可用”。

关于如何去做这件事有什么想法吗?

- 朴素的。

I wanted to know how would I go about setting the HTML of my td element as the value of a hidden field.

<td align="center">
       <%if (inst_dm != null) {%>

    ...some code..
</td>
  <%} else {%>

<td align="center"> Contact not available.
   <%}%>
  <input type="hidden" name="inst_dmhidden" value="<%$(this).html().trim(); %>">

</td>

So, what I basically want is, in the input field inst_dmhidden, either the value from (..some code..) part or 'Contact not available'.

Any thoughts about how to go about doing this?

-Pritish.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谈场末日恋爱 2024-09-22 10:42:43

为您的 td 和隐藏元素提供一个 id 或一种轻松定位的方法,就像我在这里所做的那样

<td align="center" id="mytd">
     <%if (inst_dm != null) {%>

     ...some code..
</td>
  <%} else {%>

<td align="center" id="mytd"> Contact not available.
   <%}%>
  <input type="hidden" id="myhiddenfield" name="inst_dmhidden" value="<%$(this).html().trim(); %>">

</td>

然后使用 jQuery 您可以运行此代码:

$("#mytd").html($("#myhiddenfield").val());

UPDATE

如果您不想使用 ID,则可以可以运行此代码的某些变体:

$("td").each(function(index) {
    var td = $(this);
    td.html(td.find("input[type=hidden]").val());
});

上面的代码假设隐藏字段位于 td 内部,但您可以相应地更改它。

Give your td and hidden element an id or a way to easily locate as I've done here

<td align="center" id="mytd">
     <%if (inst_dm != null) {%>

     ...some code..
</td>
  <%} else {%>

<td align="center" id="mytd"> Contact not available.
   <%}%>
  <input type="hidden" id="myhiddenfield" name="inst_dmhidden" value="<%$(this).html().trim(); %>">

</td>

Then using jQuery you could run this code:

$("#mytd").html($("#myhiddenfield").val());

UPDATE

In the case where you don't want to use IDs you could run some variant of this code :

$("td").each(function(index) {
    var td = $(this);
    td.html(td.find("input[type=hidden]").val());
});

The above code is assuming the hidden field is inside the td, but you can change that accordingly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文