jquery .live函数抛出错误“Object [object Object]没有方法'live'”

时间:2013-03-28 14:07:45

标签: javascript html jquery

我试图在项目的div ID中添加click事件但是它会抛出错误。我不知道为什么。有人可以看看代码吗?

HTML:

<div id="container">
    <div id="header1">
        <input type="button" value="Search and Highlight!!" style="position: absolute; right: 100px; top: 10px;" />
    </div>
...

jQuery的:

  var searchAttachPoint = document.querySelector('.header1');
  $('#header1').live("click", function () {
      myNameSpace.searchPrompt("Key the text and press Ok", false)
  }); // The error is thrown in this line
  var attachpoint = document.querySelector('.buttonAttachPoint');
  $(document).on('load', myNameSpace.LoadAllBooks("ajax/metadata.json", this.attachpoint));

1 个答案:

答案 0 :(得分:1)

.live()已弃用,可以替换为.on()

所以,

更改:$('#header1').live('click',function(){...})

至:$('body').on('click','#header1',function(){...})

body应替换为最近的#header1

的静态父级