Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对HTML表格单元格的Javascript更新(从数千到数百万)_Javascript_Html_Css_Html Table - Fatal编程技术网

对HTML表格单元格的Javascript更新(从数千到数百万)

对HTML表格单元格的Javascript更新(从数千到数百万),javascript,html,css,html-table,Javascript,Html,Css,Html Table,我需要在我的web报表上创建一些Javascript,将表值转换为数千或数百万(例如除以或乘以1000) 问题在于每个值都是“可点击的”(即,它被包装在锚定标记中) 这可能吗 <table class="Table" > <thead><tr> <th class="l Header" scope="col">£000s</th> <th class="l Header" scope="col">Col1</t

我需要在我的web报表上创建一些Javascript,将表值转换为数千或数百万(例如除以或乘以1000)

问题在于每个值都是“可点击的”(即,它被包装在锚定标记中)

这可能吗

<table class="Table" >
<thead><tr>
  <th class="l Header" scope="col">£000s</th>
  <th class="l Header" scope="col">Col1</th>
  <th class="l Header" scope="col">Col2</th>
</tr></thead>
<tbody>
<tr>
  <td class="l Data">   My Data Row </td>
  <td class="l Data">   <a class=nums href="javascript:MyFunc();">  11,372,397</a></td>
  <td class="l Data">   <a class=nums href="javascript:MyFunc();">  11,344,327</a></td>
</tr>
</tbody>

千英镑
可乐
可乐
我的数据行
编辑


我正在使用IE6。基本上,目标是有一个“千”和一个“百万”按钮,以便表的值可以变成11372K或11.4m等等。

我开始考虑document.getElementsByClassName('nums'),它将为您提供一个元素数组。大概是这样的:

nums = document.getElementsByClassName('nums');
for (i in nums)
   nums[i].innerHTML = nums[i]+',000';i
不过,这可能只适用于较新的浏览器,因此您可能希望在javascript框架中使用类似的方法。Jquery允许使用选择器按类名获取元素

$('.nums')

我开始考虑document.getElementsByClassName('nums'),它将为您提供一个元素数组。大概是这样的:

nums = document.getElementsByClassName('nums');
for (i in nums)
   nums[i].innerHTML = nums[i]+',000';i
不过,这可能只适用于较新的浏览器,因此您可能希望在javascript框架中使用类似的方法。Jquery允许使用选择器按类名获取元素

$('.nums')
我会用

回应您的编辑: 因为我很无聊,所以我为您编写了这段工作代码,按您认为合适的方式循环并插入'

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<table class="Table" >
<thead><tr>
  <th class="l Header" scope="col">£000s</th>
  <th class="l Header" scope="col">Col1</th>
  <th class="l Header" scope="col">Col2</th>
</tr></thead>
<tbody>
<tr>
  <td class="l Data">   My Data Row </td>
  <td class="l Data">   <a class="nums" href="javascript:MyFunc();">  11,372,397</a></td>
  <td class="l Data">   <a class="nums" href="javascript:MyFunc();">  11,344,327</a></td>
</tr>
</tbody>

<input type="button" onclick="toMillions();"> 
<input type="button" onclick="restore();"> 

<script type="text/javascript">

    $(function (){
        $.each($('.nums'), function () {
            $.data(this, "theValue", $(this).html());
        }); 
    });


    function toMillions(){
        $.each($('.nums'), function () {
            $(this).html(Number($.data(this,"theValue").replace(/,/g,"")) / 1000000 + ' million');
        });
    }

    function restore(){
        $.each($('.nums'), function () {
                $(this).html($.data(this,"theValue"));
        });
    }
</script>

千英镑
可乐
可乐
我的数据行
$(函数(){
$.each($('.nums'),函数(){
$.data(this,“theValue”,$(this.html());
}); 
});
函数toMillions(){
$.each($('.nums'),函数(){
$(this).html(数字($.data(this,“theValue”).replace(/,/g,”))/1000000+'000000”);
});
}
函数还原(){
$.each($('.nums'),函数(){
$(this.html($.data(this,“theValue”));
});
}
我会使用

回应您的编辑: 因为我很无聊,所以我为您编写了这段工作代码,按您认为合适的方式循环并插入'

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<table class="Table" >
<thead><tr>
  <th class="l Header" scope="col">£000s</th>
  <th class="l Header" scope="col">Col1</th>
  <th class="l Header" scope="col">Col2</th>
</tr></thead>
<tbody>
<tr>
  <td class="l Data">   My Data Row </td>
  <td class="l Data">   <a class="nums" href="javascript:MyFunc();">  11,372,397</a></td>
  <td class="l Data">   <a class="nums" href="javascript:MyFunc();">  11,344,327</a></td>
</tr>
</tbody>

<input type="button" onclick="toMillions();"> 
<input type="button" onclick="restore();"> 

<script type="text/javascript">

    $(function (){
        $.each($('.nums'), function () {
            $.data(this, "theValue", $(this).html());
        }); 
    });


    function toMillions(){
        $.each($('.nums'), function () {
            $(this).html(Number($.data(this,"theValue").replace(/,/g,"")) / 1000000 + ' million');
        });
    }

    function restore(){
        $.each($('.nums'), function () {
                $(this).html($.data(this,"theValue"));
        });
    }
</script>

千英镑
可乐
可乐
我的数据行
$(函数(){
$.each($('.nums'),函数(){
$.data(this,“theValue”,$(this.html());
}); 
});
函数toMillions(){
$.each($('.nums'),函数(){
$(this).html(数字($.data(this,“theValue”).replace(/,/g,”))/1000000+'000000”);
});
}
函数还原(){
$.each($('.nums'),函数(){
$(this.html($.data(this,“theValue”));
});
}

我不明白你的问题,你能说得更详细一点吗?我很想否决你提到的ie6:-(“我在使用ie6。”你是叛徒。哈哈-我们真的没有选择!ie6是公司标准!!我不明白你的问题,你能说得更详细一点吗?我很想否决你提到的ie6:-(“我在使用IE6。”你是叛徒。哈哈-我们真的没有选择的余地!IE6是公司标准!!看看这里的跨bwoser实现-应该在上面说的浏览器,我似乎有点受lisp的困扰:)。不幸的是getElementByClassName在IE8中不起作用(没有解决办法)我想说这是一个非常新的浏览器。看看这里的一个跨bwoser实现——应该在上面提到的浏览器,我似乎有点受lisp的困扰:)。不幸的是getElementByClassName在IE8中不起作用(没有解决方法)我想说这是一个非常新的浏览器。非常感谢Odge-我将在周一看这个。快速提问-这段代码在没有互联网连接的情况下可以工作吗?我需要代码在脱机模式下工作。你必须以另一种方式提供jQuery JS,但它应该可以工作。非常感谢Odge-我将在周一看这个。快速尽管如此,这段代码在没有互联网连接的情况下能工作吗?我也需要在离线模式下工作。你必须以另一种方式提供jQuery JS,但它应该能工作。