如何比较Javascript中的两个Textbox客户端ID? [英] How to Compare the Two Textbox Client Id in Javascript?

查看:87
本文介绍了如何比较Javascript中的两个Textbox客户端ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想比较两个文本框的ClientId,而不是它们的值,无论clientid等于i,还是不执行其他操作.


Hi to All,

I want to Compare the Two Textbox ClientId, not a Value of them, whether clientid is equals to i, perform something oterwise not.


for (var i = 2; i <= document.getElementById('ctl00_cphMaster_grdPaymentAmount').rows.length - 1; i++)
{
     if(document.getElementById('ctl00_chMaster_ctl04_txtPayAmount') == document.getElementById('ctl00_chMaster_ctl0' + i +'_txtPayAmount'))
     alert("Some");
}



因为我将文本框绑定到gridview,所以文本框的值与以前的值完全不同.

但是if语句匹配所有循环增量.

我该怎么办?

请帮帮我.

非常感谢.



because I bind the textbox into gridview, so the value of the textbox is entirely different to previous value.

but the if statement match all loop increment.

How can i do this?

Please Help me.

Thanks a lot.

推荐答案

您是否要测试控件是否存在,以便可以执行操作?如果是这样,请尝试这样的事情...

Are you trying to test to see if a control exists so you can perform an action if it does? If so try something like this...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <title>test</title>
    </head>
    <body>

    <span id="ctl00_chMaster_ctl04_txtPayAmount">my control text</span>

    <script type="text/javascript">

        // the fourth loop should return true all others should return false
        for(var i =1;i <= 5;i++){

            if(document.getElementById("ctl00_chMaster_ctl0" + i + "_txtPayAmount") != null){

                window.alert(true);

            }

            else {

                window.alert(false)

            }

        }



    </script>
    </body>
</html>


这篇关于如何比较Javascript中的两个Textbox客户端ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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