【问题标题】:Update Form Hidden Field Value wit button ID?使用按钮 ID 更新表单隐藏字段值?
【发布时间】:2015-06-19 18:34:47
【问题描述】:

我有一堆弹出框按钮可以打开同一个表单。现在我需要按钮 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();
        }
    });

【问题讨论】:

    标签: javascript jquery html forms twitter-bootstrap


    【解决方案1】:

    您可以在绑定到content 的函数中以this 的身份访问触发弹出框的元素。因此,您可以将代码更新为:

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

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

    【讨论】:

    • 正是我想要的!谢谢!
    猜你喜欢
    • 1970-01-01
    • 2016-12-03
    • 1970-01-01
    • 1970-01-01
    • 2021-06-27
    • 1970-01-01
    • 1970-01-01
    • 2015-09-12
    • 1970-01-01
    相关资源
    最近更新 更多