将jQuery函数应用于已加载的元素 [英] Apply jquery functions to loaded elements

查看:68
本文介绍了将jQuery函数应用于已加载的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在加载的元素上应用函数,我在网上搜索,但我不知道该怎么办.

I'm trying to apply functions on loaded element, I search the web but i don't understand what to do.

谁能告诉我该怎么做?

示例:

 <script>
 // checkbox cheque
$("#cheque").click( function () {
        if($("#cheque").is(":checked"))
        {
            //alert('Cheque is checked');
            $("#load_cheque").load("./server/mode_paiement.php?cheque=1");
        }
        else
        {
            //alert('Unchecked Cheque!!');  
            $("#load_cheque").empty();  
        }
    });
  </script>

这是要加载的元素:

<label for=" echeance " class="form-label size-120 fl-space2">Echéance: <span class="required">*</span></label> 
<input type="text" id="echeance" class="required text fl-space2 datepicker-inline" name="echeance"  /> 

您注意到存在"datepicker-inline" ..问题是datepicker无法在已加载的输入上工作

as you notice there is "datepicker-inline" .. the probleme is that datepicker is not working on the loaded input

谢谢:)

推荐答案

您应使用'实时'绑定日期选择器时,如下所示:

You should use 'live' when binding your datepicker, like this:

$('.datepicker-inline').live('click', function() {
        $(this).datepicker({showOn:'focus'}).focus();
});

(从这另一个问题上毫不客气地解除)

否则,您的日期选择器绑定代码将看不到要转换为日期选择器的新元素(它们在首次运行时不存在),您将获得当前的行为.

Otherwise, your datepicker-binding code will not see the new elements to convert to datepickers (they did not exist when it first ran), and you get your current behaviour.

这篇关于将jQuery函数应用于已加载的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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