Here is my problem. It seems that datapicker does not show up when clicked the first time on the dynamically added input (I have to click two or more times on it or best if I click above the input (label area)), does anyone see the problem. I tried a lot of live(), bind() .hasDatapicker and #datep1 variants. If possible test your answer first. Thanks.
script side:
<script>
$(document).ready(function(){
var div_data='<div id="div_data" class="data"><br />'+
'Dates from: <input type="text" id="datep1" size="10" name="data1">'+
' to: <input type="text" id="datep2" size="10" name="data2"> (Optional fields)</div>';
$("#rod_sem").after(div_data);
$(".br1").remove();
$(":input[name='pasirink']").click(function(){
var currentId = $(this).attr("id");
if (currentId == 'rod_sem')
{
$(".br1").remove();
$(".data").remove(); // this is done to prevent repetitive additions
$("#rod_sem").after(div_data); // here comes datepicker input
$("#datep1").live("click", function() {
$("#datep1").datepicker();
})
}
})
})
</script>
Html:
开发者_JAVA技巧<label id="la_rod_sem" for="rod_sem">Seminars</label>
<input type="radio" name="pasirink" id="rod_sem" value="rod_sem" checked="checked" />
<br class="br1" />
<br class="br1" />
<label id="la_rod_klaus" for="rod_klaus">Attendees</label>
<input type="radio" name="pasirink" id="rod_klaus" value="rod_klaus" />
<br />
<br />
Try with jQuery LiveQuery plugin:
$("#datep1").livequery("click", function(event) {
$(this).datepicker();
});
Change this part:
$("#datep1").live("click", function() {
$("#datep1").datepicker();
})
To this:
$("#datep1").datepicker();
The datepicker plugin is activated when the input is clicked, so you do not have to wrap this in a click event.
精彩评论