我想一個文本框的最大長度設置爲7,並停止進一步的鑰匙進入和使用的preventDefault但它給錯誤 我的代碼如下的preventDefault()不工作給予對象不支持此屬性
function crInputRK(ctrlid, ControlValue, size, clsName) {
var newTextBox = crE('input');
newTextBox.type = 'text';
newTextBox.style.fontSize = ".9em";
newTextBox.style['width'] = size;
newTextBox.style['height'] = '12px';
newTextBox.style['float'] = 'none';
newTextBox.style['margin'] = '0 0 0 10px';//added on 13feb2012
//newTextBox.maxLength = '3';
newTextBox.id = ctrlid;
newTextBox.className = 'inputDate';
//newTextBox.onchange = "javascript:return EnableButton();";
//ControlValue = getControlValue(ctrlid);
if (ControlValue != "")
newTextBox.value = ControlValue;
if (ControlValue == "Multiple")
newTextBox.disabled = true;
newTextBox.setAttribute("onkeypress", "javascript:SetMaxLength(event,this);");
return newTextBox;
}
function SetMaxLength(e, txtbox) {
var MaxLength = 7;
if (_$(txtbox.id).value.length >= MaxLength) {
e.preventDefault();
}
}
什麼是你的jQuery的版本? – Raptor 2012-03-02 09:04:32
這是你的瀏覽器? – Diode 2012-03-02 10:20:40
版本1.4.1.js – JainNavneet 2012-03-02 15:00:25