如何使用 javascript 或 jquery 以 html 形式访问 ajax 响应数据?

How to access ajax response data as html with javascript or jquery?

想象一下,有两个文件

  1. test.php
  2. index.php

在 test.php 中只有一个带有 id click 的 html 按钮。

在 index.php 中也只有一个带有 id 发送的 html 按钮。

如果我从 index.php 向 test.php 文件发送 ajax 请求,那么应该将 ID 从 test.php 中点击的按钮插入到 div 中在 index.php。现在我希望此按钮在 index.php.

中单击时隐藏 p 元素

注意:#click 按钮不应带有 onclick 属性。

怎么做? 我目前正在使用 android phone 来问这个问题。所以我无法用例子来写问题。

$("#id").live("click",function() {
 alert("hai");
})

编辑

$("#id").on("click",function() {
   alert("hai");
})

$("#id").delegate("click",function() {
   alert("hai");
})