jquery datepicker与onclick事件 [英] jquery datepicker with onclick event

查看:64
本文介绍了jquery datepicker与onclick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为文本框存储在viewstate中,所以我无法使用此JS代码

becouse textboxes are stored in viewstate i cannot use this JS code

<script type="text/javascript">
$(function() {
    $.datepicker.setDefaults($.datepicker.regional["sl"]);
    $(".inputTypeDate").datepicker({
        dateFormat: "dd.mm.yy",
        changeMonth: true,
        changeYear: true
    });
});
</script>

因为文本框的代码在源代码中不可见.

becouse code of textboxes are not visible in source code.

所以我尝试将其与onlcick事件一起使用.

so i try to use this with onlcick event.

html示例:

<p>Date: <input type="text" id="datepicker" onClick="$(function() {$( '#datepicker' ).datepicker({changeMonth: true,    changeYear: true});});"></p>

这有效,但仅当我第二次单击文本框时才有效.如何在首次点击时启用日历?

which works but only when i click second time on textbox. How to enable calendar on first click?

推荐答案

如果您有多个具有相同ID的文本框,则该文本框将无效.

If you are having multiple textboxes with the same id it will be invalid.

为文本框添加一个类名,并将处理程序绑定到那些对象.像

Add a class name for the textboxes and bind the handler to those objects. Something like

$(function(){
    $("input:text.inputTypeDate").datepicker({
        dateFormat: "dd.mm.yy",
        changeMonth: true,
        changeYear: true
    });
});


<input type="text" class="inputTypeDate" />

编辑

Edit

我不知道为什么您无法查看源代码中的元素.您是否正在动态生成元素(AJAX响应).如果它是动态创建的元素,那么您将需要使用诸如livequery之类的插件添加处理程序

I don't know why you are not able to view the element in the source code. Are you dynamically generating the element(AJAX response). If it is a dynamically created element then you will need to add the handlers using a plugin like livequery

这篇关于jquery datepicker与onclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆