偵測TextBox輸入後,字數統計的javascript,使用TextChanged有些問題
且顯示在另一個TextBox及Label寫法不同
<script type="text/javascript">
var iCount = 0;
function changeText(objElement) {
iCount = objElement.value.length;
//txt的顯示方式
var txt = document.getElementById("TextBox2");
txt.value = "剩餘字數" + (67 - parseInt(iCount));
//lab的顯示方式
document.getElementById("Label1").innerText = "剩餘字數 " + (100 - parseInt(iCount)) + " 個字";
//下面為使用MasterPage時抓取元件ID方法
document.getElementById("<%=Label1.ClientID %>").innerText = "剩餘字數 " + (100 - parseInt(iCount)) + " 個字";
}
</script>
<asp:TextBox ID="TextBox1" runat="server" Height="158px" onkeyup="changeText(this)" Width="296px" TextMode="MultiLine"></asp:TextBox>