在jquery中获取文本输入val始终为空

时间:2015-04-03 00:37:04

标签: javascript jquery html twitter-bootstrap fullcalendar

我正在获取用户在Jquery中放入文本字​​段的值,但该值为空。也许我在这里做错了或者我正在尝试访问某个东西的克隆而不是真正的元素,因为输入的值是在fullcalendar中的popover内。我正在使用bootstrap。这是我的代码。

$(document).on('click', '#saveEvent', function () {
    //save to db
    var yogaspaceid = $("#HiddenYogaSpaceId").val();
    var eventTitle = $("#eventTitle").val(); // always empty
    //var eventTitle = $("#eventTitle").attr('value'); //always emtpy
    var eventStartTime = $( "#timeSelect" ).val();
    var eventDuration = $("#timeDuration").val();
    $.post(
            '/ManageSpaces/SaveNewEvent',
            { id: yogaspaceid, title: eventTitle, startTime: eventStartTime, duration:  eventDuration}
        );
    $calPopOver.popover('destroy');
    //refresh callendar or add new event then re render
});
<div id="eventcalendar">
            <div class="col-md-10">
                <div id='fullcalendar' style="width:100%"></div>
                <div id="day-popover-head" class="hide">Add Event</div>
                <div id="day-popover-content" class="hide">
                    @*<form role="form">*@
                        <div class="form-group">
                            <label for="eventTitle">Title:</label>
                            <input type="text" id="eventTitle" class="form-control">
                        </div>

                        <div class="form-group">
                            <label for="timeSelect">Select time:</label>
                            <select class="form-control" id="timeSelect">
                                
                            </select>
                            <br>
                            <label for="timeDuration">Select duration:</label>
                            <select class="form-control" id="timeDuration">
                                <option value="30">30 min</option>
                                <option value="45">45 min</option>
                                <option value="60">60 min</option>
                                <option value="75">75 min</option>
                                <option value="90">90 min</option>
                                <option value="105">105 min</option>
                                <option value="120">120 min</option>
                            </select>
                        </div>

                    <div class="form-inline">
                        <button type="button" id="saveEvent" class="btn btn-default">Submit</button>
                        <button type="button" id="cancelEvent" class="btn btn-default">Cancel</button>
                    </div>
                    @*</form>*@
                </div>
            </div>
            <div id="eventDetails" class="col-md-2 collapse" style="background-color:yellow;">
                hello
            </div>
        </div>

1 个答案:

答案 0 :(得分:1)

不得不使用

  

var eventTitle = $(“。popover #eventTitle”)。val();

不确定为什么我必须在通话中使用.popover,但找到解决方案here