许多隐藏的 div 或替换单个 div 的内容?

发布于 2024-11-28 00:42:04 字数 197 浏览 1 评论 0原文

当用户将光标移动到我的页面上图像的不同区域时,我正在更新表格的内容,为他们提供更多详细信息。该表内容是服务器端生成的。

目前,我将大约 50 个不同的表格存储在它们自己的 div 中,这些表格在相应的鼠标悬停事件之前都是隐藏的。

这是实现这一目标的最佳方式吗?使用javascript来替换单个div的表格内容是否更好?

谢谢,A.

When the user moves their cursor over different regions of an image on my page I am updating the content of a table which gives more detail to them. This table content is generated server side.

At the moment, I am storing the 50 or so different tables within their own divs which are hidden until the respective mouseover event.

Is this the best way of achieving this? Is it better to use javascript to just replace the table content of a single div?

Thanks, A.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰葑 2024-12-05 00:42:04

好吧,如果它是 50 个具有独特内容的相同表(结构方面),我可能会选择自定义对象或类似的东西,而不是隐藏 50 个表(50 个表 = 与 1 个表相比的开销)。

使用 jQuery 尝试以下(有点伪):

var data_rows = $('#table').children('tr');
var region_information = { 
    0: { name: "Foo", location: "Loo"}, 
    1:{ name: "Bar", location: "Car" }, 
    2{ name: "Car", location: "Garage"} 
};

$('.regions').hover(
    function() {

        //Store the region for *performance*
        var this_region = $('this');        

        /* 
            Set the values in the table by getting the field corresponding to the substring
            The format = region-{n}, where {n} is a positive digit
            Repeat this `n` times, according to how many "values" you need to display per table
        */
        data_rows.children('field1').text(
            region_information[this_region.attr('name').substring(7, 1)]
        );
  }
);

这有意义吗?因为我不知道你的桌子是什么样子的,所以我不能完全告诉你该怎么做。不过,我可以为您提供类似伪代码(如上面的代码),所以我希望它可以帮助您!

Well, if it's 50 identical tables (structure-wise) with unique content, I'd probably settle for a custom object or something like that, instead of hiding 50 tables (50 tables = overhead in comparison versus 1 table).

Try the following (somewhat pseudo) using jQuery:

var data_rows = $('#table').children('tr');
var region_information = { 
    0: { name: "Foo", location: "Loo"}, 
    1:{ name: "Bar", location: "Car" }, 
    2{ name: "Car", location: "Garage"} 
};

$('.regions').hover(
    function() {

        //Store the region for *performance*
        var this_region = $('this');        

        /* 
            Set the values in the table by getting the field corresponding to the substring
            The format = region-{n}, where {n} is a positive digit
            Repeat this `n` times, according to how many "values" you need to display per table
        */
        data_rows.children('field1').text(
            region_information[this_region.attr('name').substring(7, 1)]
        );
  }
);

Did this make sense? AS I don't know what your table looks like or anything, I can't quite tell you exactly how to do it. I can however provide you with a pseudo-like code (like the one above), so I hope it helps you out!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文