Начало
Формы
Запятые
Быстро добавьте запятые к любому числовому входу формы.
Input a Number:
JavaScript Forms: Запятые
<!-- TWO STEPS TO INSTALL COMMAS: 1. Copy the coding into the HEAD of your HTML document 2. Add the last code into the BODY of your HTML document --> <!-- STEP ONE: Paste this code into the HEAD of your HTML document --> <HEAD> <SCRIPT LANGUAGE="JavaScript"> <! > <! > <!-- Begin function commaSplit(srcNumber) { var txtNumber = '' + srcNumber; if (isNaN(txtNumber) || txtNumber == "") { alert("Oops! That does not appear to be a valid number. Please try again."); fieldName.select(); fieldName.focus(); } else { var rxSplit = new RegExp('([0-9])([0-9][0-9][0-9][,.])'); var arrNumber = txtNumber.split('.'); arrNumber[0] += '.'; do { arrNumber[0] = arrNumber[0].replace(rxSplit, '$1,$2'); } while (rxSplit.test(arrNumber[0])); if (arrNumber.length > 1) { return arrNumber.join(''); } else { return arrNumber[0].split('.')[0]; } } } // End --> </script> </HEAD> <!-- STEP TWO: Copy this code into the BODY of your HTML document --> <BODY> <form name="commas"> Input a Number: <input type=text name="inpNumber" size=20 value=""> <input type=button value="Add Commas" onClick="document.commas.inpNumber.value=commaSplit(document.commas.inpNumber.value);"> </form> <!-- Script Size: 1.51 KB -->