我在 rails 应用程序中使用 fullcalender。我有以下咖啡脚本代码:
select: (start, end, allDay) ->
title = prompt("Event Title:", "")
hours = prompt("Hours", "")
if title
...
我想要一个包含两个数据字段的小弹出窗口,而不是使用 2 个提示代码行。我应该如何完成它?我应该使用引导模式吗?
谢谢
好的 --- 我创建了这个模式,它显示得很好:
<div id="calModal" class="modal hide fade" tabindex="-1" role="dialog" aria- labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Create Labor</h3>
</div>
<div class="modal-body">
<form class="form-inline" method="get">
<input type="text" id="title" class="input" placeholder="Title" name="title">
<input type="floating" id="hours" class="input" placeholder="Hours" name="hours">
</form>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>`
但是,title 和 hours 的值在我的其余咖啡脚本代码中不可用:
select: (start, end, allDay) ->
$('#calModal').modal('show')
title = $(".modal-body #title").val
hours = $(".modal-body #hours").val
if title
$.create "/events/",
event:
title: title,
starts_at: "" + start,
ends_at: "" + end,
all_day: allDay,
workorder_id: 1,
# need a modal for inputing these fields
hours: hours,
employee_id: 1
# pickup the current employee
$('#calendar').fullCalendar('refetchEvents')`
这些语句不起作用:
title = $(".modal-body #title").val
hours = $(".modal-body #hours").val