日期:2014-05-17 浏览次数:20871 次
onkeyup='value=value.replace(/[^\d]/g,"") '
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
onkeyup="this.value=this.value.replace(/\D/g,'')"
onafterpaste="this.value=this.value.replace(/\D/g,'')"
/// <summary>
/// 限制输入数字以外的字符
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textbox_KeyPress(object sender, KeyPressEventArgs e)
{
if (((int)e.KeyChar < 48
------其他解决方案--------------------
(int)e.KeyChar > 57) && e.KeyChar != 8)
{
e.Handled = true;
}
}