-1
找到這些完美的解決方案在這裏:Example禁用文本輸入 - 角與jQuery
// Catch all events related to changes
$('#textbox').on('change keyup', function() {
// Remove invalid characters
var sanitized = $(this).val().replace(/[^-.0-9]/g, '');
// Remove non-leading minus signs
sanitized = sanitized.replace(/(.)-+/g, '$1');
// Remove the first point if there is more than one
sanitized = sanitized.replace(/\.(?=.*\.)/g, '');
// Update value
$(this).val(sanitized);
});
HTML
<input type="text" id="textbox" />
,但我不能讓一個控制器內這項工作。
怎麼辦?
始終在SO上發佈相關代碼。 – Satpal