0

I make a point of placing any user-fired functions outside the $(document).ready(function () { block even though (as below) they may include jQuery elements. With the proviso that the PlaceOrder() function will not be called before the document is loaded this code works correctly.

function PlaceOrder() {
    $("#BillMe").val($("#tbReferred").val());
    confirmOrderForm.submit();
}

Should I expect the general concept to always hold true - that jQuery elements are able to be correctly resolved by any function that is assured to not fire before the DOM is ready?

4

2 に答える 2

0

いいえ、このようなユーザー定義functionの場合は、ready ブロックに含める必要があります。そうなると、外部 js ファイルなどの使用がかなり阻害されます。

于 2013-07-11T19:41:41.430 に答える
0

動的に作成され、$.click().

動的に作成された要素の場合、次のようなデリゲート関数を使用します.on()

于 2013-07-11T19:42:41.230 に答える