如何比较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>