我已动态生成文本框并尝试单独为每个文本框获取日期选择器。
问题是,如果我选择一个文本框并选择日期,它将适用于所有文本框。我不知道如何传递值来获得结果。请原谅我的英语(或)表达方式是错误的。我将感谢你的帮助。
我的脚本呼叫日历:
"""
WSGI config for website project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
from os.path import join,dirname,abspath
PROJECT_DIR = dirname(dirname(abspath(__file__)))#3
import sys # 4
sys.path.insert(0,PROJECT_DIR) # 5
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "v_bridge.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
HTML code:
<script type="text/javascript">
$(window).load( function() {
$('#mycalendar3').monthly({
mode: 'picker1',
target: '#mytarget1',
setWidth: '370px',
startHidden: true,
showTrigger: '#mytarget1',
stylePast: true,
disablePast: true,
xmlUrl: 'events.xml'
});
$('#mycalendar2').monthly({
mode: 'picker1',
target: '.value1',
setWidth: '370px',
startHidden: true,
showTrigger: '.value1',
stylePast: true,
disablePast: true,
xmlUrl: 'events.xml'
});
switch(window.location.protocol) {
case 'http:':
case 'https:':
// running on a server, should be good.
break;
case 'file:':
alert('Just a heads-up, events will not work when run locally.');
}
});
答案 0 :(得分:0)
你需要在事件上使用jquery,我在这里创建了演示小提琴,
$(function() {
$("#datepicker").datepicker();
$("button").on('click', function() {
$('.output').append('<input type="text" name="gentext" id="gent" />');
$("#gent").datepicker();
})
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h3>Normal input datepicker</h3>
<p>Date:
<input type="text" id="datepicker">
</p>
<button>generate</button>
<h3>Generated input datepicker</h3>
<div class="output"></div>
&#13;
请在您的代码上应用相同的事件,它将适用于生成的输入。