2013-04-25 12 views
16

このエラーを取得していないキャッチされない例外TypeError:このJavaScriptとjQueryのコードから</p> <pre><code>Uncaught TypeError: Object [object Object] has no method 'live' </code></pre> <p>::オブジェクト[オブジェクトのオブジェクト]は 'ライブ' 何の方法

init: function(options) { 
    var form = this; 
    if (!form.data('jqv') || form.data('jqv') == null) { 
    options = methods._saveOptions(form, options); 
    // bind all formError elements to close on click 
    $(".formError").live("click", function() { 

     //Getting error here: 
     //Uncaught TypeError: Object [object Object] has no method 'live' 

    }); 
    } 
    return this; 
}; 

なぜ方法liveが欠けていますか?

+3

まあ、 '.live()'はしばらく使われなくなりました。おそらく今は本当に消えています:) –

+4

'$(document).on( 'クリック'、 '.formError'、function(){...});' – jammypeach

+0

'.live'は1.9私は思う:http://jsfiddle.net/6mBsB/ – apsillers

答えて

7

the documentationによると、1.7とが削除されているので、.live()は廃止されました。は1.9です。

有効な場合は、jQueryをダウングレードするか、新しいバージョンの検証プラグインを使用する必要があります。

32

.liveはjqueryの中 1.9

は、ドキュメントを参照してください削除されました:http://api.jquery.com/live/


ではなく.onを使用してみてください:

$(document).on('click', '.formError', function(){ 
    //your event function 
}); 
+0

これはちょうどそれをさらに壊している、今私は2つのエラーがあり、それでも動作しません。 – Francesca

+0

@Francesca何が壊れていますか?あなたはjsfiddleを作れますか? – Neal

+0

@Francesca 2つのエラーが実際には1つの行を実際に過ぎて、存在していたが、これに関連していないより多くのエラーにさらに進んでいることを意味するでしょうか?修正後のエラーが増えることは必ずしも悪いことではありません。問題に関する詳細情報があることを意味します。 –

1

あなたは、以前のバージョンからの移行に役立つマイグレーション・ライブラリがありますアップグレード時のjQueryの:jQuery migrate plugin jQueryの後にあなたのソースにそれを含める必要があります。 jQueryのサイトから:

The uncompressed development version of the jQuery Migrate plugin includes console log output to warn when specific deprecated and/or removed features are being used. This makes it valuable as a migration debugging tool for finding and remediating issues in existing jQuery code and plugins. It can be used for its diagnostics with versions of jQuery core all the way back to 1.6.4.

The compressed version of the plugin does not generate any log output, and can be used on production sites when jQuery 1.9 or higher is desired but older incompatible jQuery code or plugins must also be used. Ideally this would only be used as a short-term solution, but that's a decision for you to make.

4

.live() removed

.live()メソッドは、jQueryの1.7以降廃止され、1.9で削除されました。代わりに.on()メソッドを使用するようにコードをアップグレードすることをお勧めします。

正確

$("a.foo").live("click", fn) 

を一致させるためには、詳細については

$(document).on("click", "a.foo", fn). 

を書くべき、.on() documentationを参照してください。その間、jQuery Migrateプラグインを追加して.live()機能を復元することもできます。

関連する問題