2014-01-21 37 views
5

我試圖在提交時獲取Bootstrap彈出窗口中的輸入值,但我得到了一個空值。Twitter Boostrap - 獲取popover textarea和輸入值

<div class="popover-markup"> <a href="#" class="trigger">Popover link</a> 
    <div class="head hide">Lorem Ipsum</div> 
    <div class="content hide"> 
     <div class="form-group"> 
      <input type="text" id="myinput" class="form-control" placeholder="Type something…"> 
     </div> 
     <button type="submit" id="mysubmit" class="btn btn-default btn-block">Submit</button> 
    </div> 
    <div class="footer hide">test</div> 
</div> 

$('.popover-markup>.trigger').popover({ 
    html: true, 
    title: 'Get value', 
    content: function() { 
     return $(this).parent().find('.content').html(); 
    } 
}); 

$(document).on("click", "#mysubmit", function() { 
    var inputval = $("#myinput").val(); 
    alert(inputval); 
    return false; 
}); 

http://jsfiddle.net/onigetoc/RvLrA/

回答

11

嘗試引用這樣的:

var inputval = $(".popover #myinput").val(); 
+2

哇,這麼快和容易的,我沒有嘗試。謝謝 – Gino

+0

@Gino歡迎您,如果能解決您的問題,請將此答案標記爲已接受。 (答案左邊有一個白色的複選標記,你可以點擊)謝謝 – Trevor

+0

@Trevor,我知道這是一箇舊的答案,但我很困惑,爲什麼這個答案有效,$(「#myinput 「).val()不?有什麼區別(除了指定看看.popover裏面的#myinput)這是否會產生? – Alex