2017-06-01 30 views
0

我有類似的this完整的日曆,你可以看到你可以創建事件寫入輸入並點擊按鈕。獲取選定的值來添加事件fullCalendar

而不是我有一個選擇我想創建具有選定值的事件,有沒有posible?

HTML:

<select id="lstRegion" class="form-control select2 select2-accessible agenda_space" aria-hidden="true"></select> 
<a href="javascript:;" id="event_add" class="btn green"> Add Event </a> </div>     
<div id="event_box" class="margin-bottom-10"></div> 

JS:

//load region dropdown 
     $("#lstRegion") 
       .getJSONCatalog({ 
        onSuccess: function (response) { 
         console.log(response); 
        }, 
        url: '/Agenda/GetRegion', 
        valueProperty: "ID", 
        textProperty: "valor" 
       }); 

//Event logic 
var initDrag = function (el) { 
    // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/) 
    // it doesn't need to have a start or end 
    var eventObject = { 
     title: $.trim(el.text()) // use the element's text as the event title 
    }; 
    // store the Event Object in the DOM element so we can get to it later 
    el.data('eventObject', eventObject); 
    // make the event draggable using jQuery UI 
    el.draggable({ 
     zIndex: 999, 
     revert: true, // will cause the event to go back to its 
     revertDuration: 0 // original position after the drag 
    }); 
}; 
var addEvent = function (title) { 
    title = title.length === 0 ? "Untitled Event" : title; 
    var html = $('<div class="external-event label label-default">' + title + '</div>'); 
    jQuery('#event_box').append(html); 
    initDrag(html); 
}; 

$('#external-events div.external-event').each(function() { 
    initDrag($(this)); 
}); 

$('#event_add').unbind('click').click(function() { 
    var title = $('#event_title').val(); 
    addEvent(title); 
}); 
+0

因此,不是用戶輸入的文本,而是想要選擇事件的下拉菜單? *我想創建具有選定值的事件,有沒有可能?*是的,這是可能的。 – Twisty

+0

是的,我的下拉菜單中有值,所以我想通過文本選擇值。我怎麼能這樣做@Twisty – Gerardo

回答

1

如果你有這樣的代碼:

<select id="lstRegion" class="form-control select2 select2-accessible agenda_space" aria-hidden="true"> 
    <option>Appointment</option> 
    <option>All Day Event</option> 
    <option>Meeting</option> 
</select> 

你將要使用:

$('#event_add').unbind('click').click(function() { 
    var title = $('#lstRegion option:selected').html(); 
    addEvent(title); 
}); 

這將從<select>中選擇當前選擇的選項,然後閱讀<option>innerHTML

+0

有一個問題,如果我有多個選擇,我想連接他們,我不能做這樣的事情:'var title = $('#lstRegion option:selected'+' - '+ '#lstProveedor選項:選中')。html();'?我嘗試它,但我得到錯誤 – Gerardo

+0

@Gerardo,不,這不是合併它們的正確方法。在兩個對象之間使用'+'運算符,而不是在選擇器中。 – Twisty

+0

@Gerardo'var title = $('#lstRegion option:selected')。html()+' - '+ $('#lstProveedor option:selected')。html();' – Twisty