【问题标题】:Reloading jQuery after AJAX Div LoadAJAX Div 加载后重新加载 jQuery
【发布时间】:2013-06-03 02:51:41
【问题描述】:

我使用 ajax 加载我在 php 中的一些代码

function loadNewcomment(divID) {
$.ajax({
        url: templateUrl+"/enternote.php",
        cache: false,
        success: function(html){
            $("#"+divID).append(html);

        }
    });
}

我在 $(document).ready(function(){ }); 中有这段代码但它没有检测到新的 DIV,我该如何重新加载那部分代码?

$keyPressed = 0;
    $(".note-field").keyup(function(event){
        var thisString = $(this).val();
        $keyLength = thisString.length;
        $rowCount = Math.ceil($keyLength/40);
        $currentRow = $(this).attr("rows");

        if($currentRow < $rowCount){
            $(this).animate({rows:$rowCount},50);
       }

【问题讨论】:

    标签: jquery ajax html dynamic reload


    【解决方案1】:

    在这种情况下,您需要event delegation。

    替换

    $(".note-field").keyup(function(event){
    

    有

    $(document).on('keyup', '.note-field', function(event){
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-23
      • 2013-07-10
      • 2014-09-06
      • 1970-01-01
      • 2021-05-31
      • 2017-03-15
      • 1970-01-01
      相关资源
      最近更新 更多