gpt4 book ai didi

javascript - 使用按钮 ID 更新表单隐藏字段值?

转载 作者:行者123 更新时间:2023-12-02 16:03:59 25 4
gpt4 key购买 nike

我有一堆弹出按钮,可以打开相同的表单。现在我需要按钮 id 值作为表单内的隐藏字段。

html 按钮:

<a type="button" class="pop" data-toggle="popover" id="1">Button 1</a>
<a type="button" class="pop" data-toggle="popover" id="2">Button 2</a>
<a type="button" class="pop" data-toggle="popover" id="3">Button 3</a>
...

弹出窗口形式:

<div id="popover-content" class="hide">
<form>
<input name="name" type="hidden" value="ButtonIDvalue">
...

弹出窗口js:

$('.pop').popover({ 
html : true,
content: function() {
return $("#popover-content").html();
}
});

最佳答案

您可以在绑定(bind)到 content 的函数中以 this 的形式访问触发弹出窗口的元素。因此您可以将代码更新为:

$('.pop').popover({ 
html : true,
content: function() {
$('#hidden-input').val(this.id);
return $("#popover-content").html();
}
});

当然,为隐藏的输入字段使用正确的选择器。

关于javascript - 使用按钮 ID 更新表单隐藏字段值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30945066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com