无法从Bootstrap弹出窗口中的输入元素获取值 [英] Unable to fetch values from an input element in Bootstrap's popover
本文介绍了无法从Bootstrap弹出窗口中的输入元素获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从放置在Bootstrap Popover中的某些输入字段中获取值.但是我得到的是空字符串.
I'm trying to fetch values from some input fields that are placed in a Bootstrap Popover. But I get empty string.
复杂度:表单中有一个按钮,当您单击此按钮时,将显示一个弹出窗口,其中包含2个输入字段和一个按钮.单击按钮时,我想捕获这两个字段的值.如果我将这些字段放在表单中,那么它将变成嵌套表单.
Complexity: There is a button within a form, when you click this button a popover appears with 2 input fields and a button. I want to capture the values of these 2 fields when we click the button. If I put these fields in a form, then it would become nested forms.
以下是我的代码.
<button type="button" class="btn btn-danger popper hyperlink" data-toggle="popover">Trial</button>
<div class="popper-content hide">
<input type="text" class="form-control" id='urlLabel' placeholder="URL Label">
<input type="text" class="form-control url" id='url' placeholder="Complete URL">
<button type="button" class="btn btn-default btn-block urlDetails">Done</button>
</div>
我获取值的方式
$('.urlDetails').click(function(){
console.log('clicked');
console.log($('#urlLabel').val());
console.log($('#url').val());
})
这是我的 JSFiddle ,涉及上述情况.
Here is my JSFiddle covering the above case.
推荐答案
Try following code:
$(document).ready(function() {
$(document).on('click', '.urlDetails', function() {
console.log('clicked');
console.log($('.popover-content').find('#urlLabel').val());
console.log($('.popover-content').find('#url').val());
})
});
这篇关于无法从Bootstrap弹出窗口中的输入元素获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文