我想我错过了一些东西。即使在文档准备好之后,即使我通过附加动态创建了元素,我不应该访问它们吗?例如,我可以使用 jQuery .hide()
,但可以访问相同的元素来使用日期选择器。动态测验形式如下。
$(document).ready(function() {
var question_id = 1;
var answer_id = 1;
// answer count, where i = question_id;
var answer_count = new Array();
// Create Quiz
$('.create_quiz').click(function() {
$('.create_quiz').hide();
$('<div></div>').appendTo('form');
$('<label>Quiz Name: </label><input type="text" name="quiz_name">').appendTo('form>div');
$('<label class="total_pnts">Total Points: </label><input type="text" id="total_points" style="width:05%" name="total_points">').appendTo('form>div');
$('<label class="date_assig">Date Assigned: </label><input type="text" id="date_assigned" style="width:05%" name="date_assigned">').appendTo('form>div');
$('<label class="due_dte">Due Date: </label><input type="text" id="due_date" style="width:05%" name="due_date">').appendTo('form>div');
$('<br/>').appendTo('form>div');
$('<button type="button" class="add_question">Add Question</button>').appendTo('form>div');
$('<input type="submit" value="Save Quiz">').appendTo('form');
/* WHAT WRONG WITH $('#due_date').datepicker(); RIGHT HERE
The DOM is available. I have all my jQuery and plugins correct so
no need to state any of that kind stuff. */
});
// Add Question Button
$('form').on('click', '.add_question', function() {
$('.total_pnts').hide();
$('#total_points').hide();
answer_count[question_id] = 0;
$('.add_question').hide();
$('<div class="question" id="' + question_id + '"></div>').appendTo('form>div');