【发布时间】:2018-03-18 16:24:35
【问题描述】:
我有 6 个具有不同 ID(#One、#Two、#Three...)的隐藏 div,它们通过图像点击显示,每个都有不同的类(.one-trigger、.two-trigerr.... )。
每个隐藏的 div 都有不同的标题,具有相同的类和相同的形式。
表单包含一个没有值的隐藏字段。
我正在尝试根据不可见的 div 或单击的触发器获取隐藏字段值中的标题文本。
这是 html 标记:
<img class="one-trigger"/>
<img class="two-trigger"/>
.
.
.
<div id="One">
<h2 class="get-title">this is the title 1</h2>
<form>
<input type="hidden" name="the-title" id="the-title" value=""/>
</div>
<div id="Two">
<h2 class="get-title">this is the title 2</h2>
<form>
<input type="hidden" name="the-title" id="the-title" value=""/>
</form>
</div>
到目前为止,我尝试了这个 jquery 代码,它获取标题文本,但在显示不同的 div 时不会改变:
$(function() {
$('input[name="the-title"]').val($(".get-title").text());
});
任何帮助将不胜感激!
【问题讨论】:
标签: jquery hidden-field