-1
我正在使用Javascript [僅限初學者]計算點的「剩餘點」。Javascript:keypress/keycode
樣品GUI:
場景:
我輸入22 spots
然後後,我點擊txtA的Remaining Spots is already "22" [it should be "21"
]之外txtA I input 1
。但是當我試圖change the value of txtA to "2"
現在剩下的景點已經是"21" [it should be "20"]
。
代碼爲我的ASP.NET
protected void txtA_TextChanged(object sender, EventArgs e)
{
txtRemaining.Text = (Convert.ToInt32(txtSlot.Text) - Convert.ToInt32(txtA.Text)).ToString();
}
protected void txtSlot_TextChanged(object sender, EventArgs e)
{
int slot= Convert.ToInt32(txtSlot.Text);
txtRemaining.Text = Convert.ToString(slot);
}
的Javascript:
function checkIt(evt) {
evt = (evt) ? evt : window.event
var charCode = (evt.which) ? evt.which : evt.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false
}
status = ""
var comp1= document.getElementById("<%= __txt67Value1.ClientID %>").value;
var comp2 = document.getElementById("<%= txtSlot.ClientID %>").value;
document.getElementById("<%= txtRemaining.ClientID %>").value = comp2- comp1;
return true
}
在此先感謝...
你如何觸發'checkIt'? - 標題不僅僅是一系列關鍵字,請讓它更好一點...並用瀏覽器調試您的代碼 – Aristos