English 中文(简体)
缩略语:加上2个数学数值,然后以超文本计算。
原标题:Math in jQuery: adding 2 variables math value together and then outputting them in HTML
  • 时间:2011-10-19 22:30:42
  •  标签:
  • jquery

我正试图吸收2个变量,就这些变量进行数学,然后将其作为新的3个变量进行产出。 我试图这样做的基本逻辑是:

var A1 = [+ditto_iteration+]
var B1 = [+gallery_currentPage+]
var C1 = (B1-1)*3+A1+1

然后,我需要将变数C和产出的价值作为一些超文本处理,以便:

<a href="variable C1 here">link</a>

因此,为了澄清,我先提出一些方案,在页数上产生[+ditto_iteration+]的价值。 Same with [+gallery_ CurrentPage+]. 我只需要掌握A1和B1的变量值,进行上文所示的数学,然后用数学操作所产生的价值取代URL的变量(C1)。

最佳回答
<script>
var A1 = parseInt([+ditto_iteration+]);
var B1 = parseInt([+gallery_currentPage+]);
var C1 = (B1-1)*3+A1+1;

$( #link ).attr( href , C1);

</script>


<a id= link  href="variable C1 here">link</a>
问题回答
var A1 = 10,
    B1 = 30,
    C1 = (B1 - 1) * 3 + A1 + 1;

$( a ).attr( href , C1).text( C1 value is   + C1);

Live here http://jsfiddle.net/q3EL3

if you give the element an id like so:

<a id="c1val" href="variable C1 here">link</a>

你们可以更容易地这样做。

背 景

$("a#c1val").attr("href",C1 +   ); //Adding empty string makes C1 a string

没有补贴(只有一次工作)

$( a[href="variable C1 here"] ).attr("href",C1 +   ); //Adding empty string makes C1 a string




相关问题
getGridParam is not a function

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 )...

selected text in iframe

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.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

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.

jConfirm with this existing code

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"; } ...

Wrap text after particular symbol with jQuery

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: &...

热门标签