どのように私はasp.netのテキストボックスに3桁の後にドットを置くことができますか?以下のコードは私のためには機能しません。私はそれがほんのjaveryではないjavascriptをしたい。あなたの助けに感謝...どのように私はネイティブのJavaScriptによってasp.netのテキストボックスに3桁の後にドットを置くことができますか?
Forexample:
1234:1.234 23456: "" 23.456 しかし、私は "COMMA" を置けば、それは入れて停止する必要があります1.2345,78 カンマにはイベントを停止するイベントがあると思います。
これは最初の答えは「Can jQuery add commas while user typing numbers?」です。カンマではなく、「ドット」をカンマではなく使用します。しかし、私はカンマの許可が必要です。
私のC#コード:
private void GvRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox txtVeri = (TextBox)e.Row.FindControl("txtVeri");
txtVeri.Attributes.Add("onkeyup", "InsertComma(this.id)");
}
}
私のJSコード:あなたはクリックイベントまたは他のそのようなイベントで検証する場合
function InsertComma(veriId) {
console.log("çalışıyor");
var txtObj = document.getElementById(veriId);
var txtVal = replaceAll(txtObj.value, '.', '');
//alert(txtObj.value);
if (txtObj.value != "") {
var newVal = "";
for (var i = 0; i < txtVal.length; i++) {
//alert(txtVal.substring(i, 1));
newVal = newVal + txtVal.substring(i, i + 1);
if ((i + 1) % 3 == 0 && i != 0 && i + 1 < txtVal.length) {
newVal = newVal + ".";
}
}
txtObj.value = newVal;
}
}
function replaceAll(txt, replace, with_this) {
return txt.replace(new RegExp(replace, 'g'), with_this);
}