私はいくつかの機能をページの$(document).ready(function(){
に使用しています。
新しい機能(上に追加)を追加するまで、古い機能(下に強調表示されています)は正常に機能しました。それ以来、彼らはもはや働かない。 いくつかのテストの後、私は古い機能と新しい機能の間でポジションを切り替えると、上に配置された機能だけが機能することに気付きました。
私は以前のものとは別のページで新しい機能を使用していますが、どちらもjavascriptファイルとフッターに含まれています。
home.js:私は "古い機能" を使用して、ページをロードする場合
$(document).ready(function(){
// NEW FUNCTION (up/down arrows)
var nextListitem;
var noOfListItems = $("#select > option").length-1;
var curListItem = $("#select")[0].selectedIndex;
$("#upArrow").on("click", function(){
// Decrement the selection by one, unless that will be less than zero, then go to the last option
nextListitem = (curListItem-1 < 0) ? noOfListItems : curListItem-1;
curListItem = nextListitem;
$("#select")[0].selectedIndex = nextListitem;
});
// OLD FUNCTIONS (count characters left in textarea)
window.com_domain = window.com_domain || {};
$(':text,#resort_description').click(function(){
current_input_val = $(this).val();
$(this).select();
}).focusout(function(){
if ($(this).val() == '') {
$(this).val(current_input_val);
}
});
// more old functions
});
TypeError: $(...)[0] is undefined
var curListItem = $("#select")[0].selectedIndex;
が表示されます。
これは(jqueryのを前に呼ばれている)のように、私のフッターがどのように見えるかです:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.1/jquery.min.js"></script>
<script src="js/bootstrap-hover-dropdown.min.js'>"></script>
<script src="js/home.js" type="text/javascript"></script>
は、あなたが質問に関連していない任意のコードを削除でしたファイルのjs縮小さbootstarpのインポートにmistkeを持っていると思いますか? – evolutionxbox
'id ="を持つ要素がありますか?そうでない場合、そのエラーは関数をそこで停止させます。 – Barmar
ページのHTMLを表示します。 – Barmar