如何从popover到textbox解析值?
我想从弹出窗口中的下拉框中将值解析为输入文本。 我可以让它弹出但不能插入选定的值。 由于某些原因,我不需要在弹出窗口中选择。
HTML
Choose your option
one two option> OK
JS
$("[data-toggle=popover]").popover({ html: true, content: function() { return $('#popover-content').html(); } }); var selectVar = $('#select').val(); $('#optBtn').click(function() { $('#input').val(selectVar); })
在这里小提琴: https : //jsfiddle.net/723exh1g/3/
你以错误的方式绑定了元素。 试试这个 –
$(document).on('click','#optBtn',function() {//can be hide after select var selectVar = $('#select').find('option:selected').val(); alert(selectVar) $('#input').val(selectVar); })
嗨你可以试试这个。
$("[data-toggle=popover]").popover({ html: true, content: function() { return $('#popover-content').html(); } }).parent().delegate('#optBtn', 'click', function() { var selectVar = $('#select').val(); $('#input').val(selectVar); alert(selectVar); });
感谢@nikhil_gandhi和@PhaniKumarM的帮助。 最终代码如下:
$("[data-toggle=popover]").popover({ html: true, content: function() { return $('#popover-content').html(); } }); $(document).on('click','#optBtn',function() {//can be hide after select var selectVar = $('#select').find('option:selected').val(); $('#input').val(selectVar); $('.popover').hide(); })