【问题标题】:Jquery, append content from urlJquery,从url附加内容
【发布时间】:2011-07-08 12:45:41
【问题描述】:

是否可以从 Jquery 的文件中附加一些 html 内容?

我知道你可以在 jquery 中使用 load() 来替换元素中的全部内容。

但我想知道是否可以有条件地使用 append('url') 将额外内容添加到 Jquery 中的元素中

【问题讨论】:

    标签: jquery url append add


    【解决方案1】:

    你可以试试这个:

    $.get('/someurl', function(result) {
        $('#someElement').append(result);
    });
    

    【讨论】:

      【解决方案2】:

      所以您正在尝试附加动态内容?试试这样的:

      $(document).ready(function(){
        $.get('<URL>', function(data){
          $(<contentelement>).append(<either entire data element, or do some operations on it>);
        });
      });
      

      【讨论】:

        【解决方案3】:

        是的,你可以。 append() 在元素末尾附加了一些内容。

        【讨论】:

          【解决方案4】:

          另一种方法是执行两步过程,即

          onclick='$("#id1").append("<div id=\"id2\"></div>"); $("#id2").load("content.php");'
          

          这也适用于从另一个网址添加内容。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-05-26
            • 2010-11-20
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多