简体   繁体   English

向Tiptip jQuery添加变量

[英]Adding a variable to tiptip jQuery

I couldn't think of a more descriptive title, so I do hope it makes sense (feel free to correct me if I am wrong). 我想不出一个更具描述性的标题,所以我希望它有意义(如果我错了,请随时纠正我)。

Basically I am adding tables to a site and the columns will automatically resize according to the amount of columns being added. 基本上,我将表添加到站点,并且列将根据要添加的列数自动调整大小。 Adding a single works perfectly well, where it's getting a bit complicated for me (perhaps over the head) is as soon as I add an additional table on the same page - the script which runs counts all of the columns in their entirety. 添加单个文件的效果非常好,对我来说可能有点复杂(也许太过头了),因为我在同一页上添加了另一个表-运行的脚本会完整地计算所有列。
For instance, if I add a three column table at the top of the page then and additional three column table at the bottom - the script then counts a total of 6 columns then divides 100 by that number.. 例如,如果我在页面顶部添加了一个三列表,然后在底部添加了另外三列表,那么脚本将计算总共6列,然后用该数字除以100。

Is there a simple way to create a variable or a table count so that the script at the bottom detects separate tables and resizes the columns per table? 是否有一种简单的方法来创建变量或表计数,以便底部的脚本检测单独的表并调整每个表的列大小?

Snippets of the code below: 以下代码片段:

<div class="table<?php echo $tblid; ?>">
        <div class="cols">
        </div>

    ..code going on here..
        <div class="cols">
        </div> 
    ..Some more code going on here..
</div>

    var v = jQuery('.table .cols').length;

    var cw = (100/v);

    jQuery('.table .cols').css('width',cw+'%');

If i am not wrong, youu have two tables with the same classname , so your selector jQuery('.table .cols') gets both the table and jQuery('.table .cols').length; 如果我没看错,则您有两个具有相同类名的表,因此您的选择器jQuery('.table .cols')获取表和jQuery('.table .cols').length; will give you the length of the cols combining both the tables... 将为您提供合并两个表格的列的长度...

what you can do is. 你能做的是。 Give them seperate class and call each one.. 给他们单独的课,然后给每个人打电话。

HTML 的HTML

 <div class="table1">
    <div class="cols">
    </div>

  ..other code going on here..

</div>

<div class="table2">
    <div class="cols">
    </div>

  ..other code going on here..

</div>

Jquery jQuery的

jQuery(function(){
  jQuery('div[class^="table"]').each(function(){
    var obj=jQuery(this).find('.cols');
    var v = obj.length;
    var cw = (100/v);

    obj.css('width',cw+'%');
  });
});

this should work for any number of tables.. 这适用于任何数量的表。

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

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