【问题标题】:jQuery add div to another pagejQuery 将 div 添加到另一个页面
【发布时间】:2012-08-04 15:22:33
【问题描述】:

我正在做一个小管理面板,想知道是否可以在单击面板中的按钮后使用 jQuery 在 index.php 文件中添加一个 div 框?

如果是这样,一个小例子将不胜感激!

【问题讨论】:

  • 谷歌会很快回答这个问题。

标签: php jquery html panel add


【解决方案1】:

您需要使用 jQuery 的$.post() 方法发送一个 XML http post 请求,然后让服务器上的 php 文件修改索引文件,或者可以包含在索引文件中的文本文件:

$.post('indexEdit.php', {info: "info to ad to file"}, function(data){ /*callback here*/ });

确保 indexEdit.php 具有会话验证,否则其他人可能会尝试向其发布信息并执行外部编辑。

【讨论】:

    【解决方案2】:

    要将代码添加到 div 的开头,请使用 prepend 方法。要将代码添加到 div 的末尾,请使用 append 方法。

    以下是向 html 页面正文添加代码的 2 个示例:

    $("body").prepend("This is some div added to the start of the page.");
    $("body").append("This is some div added to the end of the page.");
    

    如果您想动态加载内容,则必须使用ajax 方法并在回调中使用上述代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-24
      • 2012-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-03
      • 1970-01-01
      相关资源
      最近更新 更多