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

如何使用javascript或jquery以html的形式访问ajax响应数据?,javascript,jquery,html,ajax,response,Javascript,Jquery,Html,Ajax,Response,想象一下,有两个文件 test.php index.php 在test.php中,只有一个id为click的html按钮 在index.php中,也只有一个id为send的html按钮 如果我从index.php向test.php文件发送ajax请求,那么id为click from test.php的按钮应该插入index.php中的div中。现在我想让这个按钮在index.php中单击p元素时隐藏它 注意:onclick属性不应与#click按钮一起提供 怎么做? 我现在用安卓手机问这个问题。

想象一下,有两个文件

  • test.php
  • index.php
  • 在test.php中,只有一个id为click的html按钮

    在index.php中,也只有一个id为send的html按钮

    如果我从index.php向test.php文件发送ajax请求,那么id为click from test.php的按钮应该插入index.php中的div中。现在我想让这个按钮在index.php中单击p元素时隐藏它

    注意:onclick属性不应与#click按钮一起提供

    怎么做? 我现在用安卓手机问这个问题。所以我不能用例子来写这个问题

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


    .live()
    在jQuery 1.7中被弃用,并在1.9中被删除。你不应该推荐它,使用<代码>。()<代码> > @ KirenSiva,请考虑修改你的答案!这些都不行。它们依赖于存在的元素。(嗯,
    delegate
    可能会起作用,但我从来没有用它来支持
    $(someParentElement)
    
    $("#id").on("click",function() {
       alert("hai");
    })
    
    $("#id").delegate("click",function() {
       alert("hai");
    })