如何在jQuery中编写以下代码语法 [英] How to write below code syntax in jquery

查看:83
本文介绍了如何在jQuery中编写以下代码语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经用JavaScript编写了一个代码,该代码在chrome和IE浏览器中可以正常工作,但不能与Mozilla一起使用.
因此,在jquery中编写它很好,但是我对jquery还是陌生的.
您能帮我在jquery中编写以下代码吗?

Hello all,

I have written a code in JavaScript that is working fine in chrome and IE browsers but not working with Mozilla.
So its good to write that in jquery but I am new to jquery.
Can you help me to write the below code in jquery.

<script type="text/javascript" language="javascript">
function getMult()
{
   for(var i=2;i<=ctl00_ContentPlaceHolder1_GridView1.rows.length;i++)

   {

     var a=parseFloat(document.getElementById("ctl00_ContentPlaceHolder1_GridView1_ctl0"+i+"_txtqty").value);

     var b=parseFloat(document.getElementById("ctl00_ContentPlaceHolder1_GridView1_ctl0"+i+"_txtrate").value);

     var c=parseFloat(document.getElementById("ctl00_ContentPlaceHolder1_GridView1_ctl0"+i+"_txtamt").value);

     var total=a*b;

     parseFloat(document.getElementById("ctl00_ContentPlaceHolder1_GridView1_ctl0"+i+"_txtamt").value=total.toFixed(2));

   }

}

</script>

推荐答案

要遍历网格中的行,请使用网格的ID或类,然后在tbody-> tr元素上使用each()函数.
然后,可以在循环中使用 this 关键字,该关键字将引用网格中的每一行.

然后,您只需从单元格中提取值,即可在此处使用各种方法,例如children()函数

将#YourGridID替换为您的网格ID,这将在&只需将第一个单元格的值读入变量即可.这应该启动您,看看您是否可以完成

To iterate over rows in a grid, you use the ID or class of the grid and then use the each() function over the tbody->tr elements.

Within the loop, you can then use the this keyword which will refer to each row in the grid.

Then you just extract values from the cells, you can use various methods here, such as the children() function

Replace #YourGridID with the ID of your grid, this will start a loop over the rows & just read in the value of the first cell into a variable. This should start you up, see if you can finish

function getMult() {


(' #YourGridID tbody tr').each(function(){ var celltext =
('#YourGridID tbody tr').each(function() { var celltext =


( this ).children(" ).text(); }); }
(this).children(":first").text(); }); }


这篇关于如何在jQuery中编写以下代码语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆