我的目標是每當我插入到textbox1中,它都會自動在TextBox2中更新。我不想使用「輸入標籤」或回發。請僅在下面的代碼中糾正:)如何通過asp.net C#控制ID在Javascript函數中的多個參數
<script type="text/javascript">
function OneTextToother1(a, b) {
alert(a.value); //it render correct value
alert(b.value); // it is undefined
document.getElementById(b).value = document.getElementById(a).value
}
</script>
<asp:TextBox ID="txtFirst" runat="server" onkeyup="OneTextToother1(this, ' <%= txtSecond.ClientID %>');" ></asp:TextBox>
<asp:TextBox ID="txtSecond" runat="server"></asp:TextBox>
正如John Answer所示。我能夠實現他的建議。請僅修改上述代碼。我想要有通用的JS函數,並且在asp文本框聲明中,我將傳遞源和目標clientID。它可以實現嗎?
'a'是一個DOM節點,'b'是一個字符串(帶有前導空格) – Andreas
'FirstTextBox.nextElementSibling = secondTextBox',你不需要傳遞第二個'textbox'。 –