gpt4 book ai didi

javascript - 在控制台中的 DOM 中插入 HTML 代码后出错(Chrome 浏览器)

转载 作者:行者123 更新时间:2023-12-03 05:55:44 26 4
gpt4 key购买 nike

获取 HTML 行:room["html"] = $(this).parents(".selectRowRoom").html(); 并在加载 step-02 后插入。 php.thisRoom 中,但此错误出现在控制台中。

$(function () {
var hotel = [];
var lenHotel = 0;
$('#forPrice').on('click', function() {
$('select').each(function() {
if($(this).val() > 0 && $(this).val() < 10) {
var room = {};
room["room"] = $(this).attr('room');
room["price"] = $(this).attr('price');
room["val"] = $(this).val();
room["html"] = $(this).parents(".selectRowRoom").html();

hotel.push(room);
}
});
lenHotel = Object.keys(hotel).length;
console.log(hotel);
});

$('#forPrice').click(function () {
$('#Step-01').hide();
$('#Step-02').show();
$('.hiddenAndShow').hide();
$( "#Step-02" ).load( 'step_02', function () {
for(var i = 0; i <= lenHotel; i++) {
$("#Step-02").find('.thisRoom').append("<tr class=\"selectRowRoom\">");
$("#Step-02").find('.thisRoom').append(hotel[i]['html']);
$("#Step-02").find('.thisRoom').append("</tr>")
}
});
});
})

控制台中的错误是:

Uncaught TypeError: Cannot read property 'html' of undefined

最佳答案

这个...

 for(var i = 0; i <= lenHotel; i++) 

应该是这个

for(var i = 0; i < lenHotel; i++) 

您访问的数组中不存在的元素。

关于javascript - 在控制台中的 DOM 中插入 HTML 代码后出错(Chrome 浏览器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39936707/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com