我有一个带有数字价值的超文本表格。 我需要做的是,利用 j子把所有这些价值观加在一起。
任何想法?
例表:
页: 1
var sum = 0;
$( table td ).each(function() {
sum += parseFloat($(this).text());
});
我会给你一些假装的密码,说明我是如何做的(主要因为我无法做全事)。
.each()
to loop through each tr
.td
and add the value to the relevant total.tr
have been looped through, do whatever you want :)希望有助于你们:
EDIT:我写的是,如果你想要把每栏一整起来,而不是把所有囚室一整一整。
这一点已经得到答复。 因此,就象 exercise:
// Give all arrays the power of summation
Array.prototype.sum = function(){
for( var i=0,sum=0;i<this.length;sum+=this[i++] );
return sum;
}
// Use map for kicks
$(document).ready( function(){
var result = $( table#mytable tr td ).map( function(){
return parseFloat( $(this).text() );
}).get().sum();
});
The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...
How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.
I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...
I have a div <div id="masterdiv"> which has several child <div>s. Example: <div id="masterdiv"> <div id="childdiv1" /> <div id="childdiv2" /> <div id="...
I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.
I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...
Ok, I m stumped. Basically, this script works fine in FF, but not in IE (6,7 or 8) - in which it returns an "Object doesn t support this property or method" error. Any ideas?: function ...
What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...