简体   繁体   English

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

[英]many hidden divs or replacing content of single div?

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. 目前,我正在将50个左右的不同表存储在自己的div中,这些表将一直隐藏到相应的mouseover事件发生为止。

Is this the best way of achieving this? 这是实现这一目标的最佳方法吗? Is it better to use javascript to just replace the table content of a single div? 使用javascript替换单个div的表内容是否更好?

Thanks, A. 谢谢。

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). 好吧,如果它是50个相同的表(在结构方面)且具有唯一的内容,我可能会选择一个自定义对象或类似的东西,而不是隐藏50个表(50个表=比较中的开销与1个表)。

Try the following (somewhat pseudo) using jQuery: 使用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! 不过,我可以为您提供类似伪代码的代码(如上述代码),因此希望它对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM