|
Цитата:
Подскажите, пожалуйста, у меня есть инпут, в котором работает пробел при изменении. А как сделать пробел сразу при загрузке страницы? <input type="text" value="3432424" id="cif" /> <script> var input = document.getElementById("cif"); input.onkeyup = input.onchange= input.onpaste = function(){ this.value= this.value.replace(/\s+/g, "").match(/(\d{1,3})(?=((\d{3})*([^\d]|$)))/g).join(" "); }; </script> |
У меня получилось так:
<body onload="ly()"> <input type="text" value="3432424" id="cif" /> <script> var input = document.getElementById("cif"); input.onkeyup = input.onchange= input.onpaste = function(){ this.value= this.value.replace(/\s+/g, "").match(/(\d{1,3})(?=((\d{3})*([^\d]|$)))/g).join(" "); }; function ly(){ input.value = input.value.replace(/\s+/g, "").match(/(\d{1,3})(?=((\d{3})*([^\d]|$)))/g).join(" "); } </script> </body> Может есть более изящный способ :) ? |
qwe88,
<body onload="input.onkeyup()"> <input type="text" value="3432424" id="cif" /> <script> var input = document.getElementById("cif"); input.onkeyup = input.onchange= input.onpaste = function(){ this.value= this.value.replace(/\s+/g, "").match(/(\d{1,3})(?=((\d{3})*([^\d]|$)))/g).join(" "); }; </script></body> |
Вот это некропост, лол.
|
Часовой пояс GMT +3, время: 15:37. |