2016-04-08 12 views
0

値が挿入された入力ボックス(すべての整数)があります。私は彼らがこの二つの写真のように示すことにしたい。入力値の外側をクリックした後に入力値を追加します

1:

1st

2:

2nd

$(document).ready(function() { 
 
    $("input").each(function() { 
 
    $(this).blur(function() { 
 
     var len = $(this).val().length; 
 

 

 
    }); 
 
    }); 
 

 
});
.ndInbox { 
 
    background-color: white; 
 
    width: 390px; 
 
    height: 42px; 
 
    box-shadow: 0 2px 2px 0 #C2C2C2; 
 
    border: none; 
 
    outline: none; 
 
    font-size: 18px; 
 
    margin-bottom: 10px; 
 
    font-family: 'PT Sans', sans-serif; 
 
    padding-left: 10px; 
 
} 
 
.ndLabel { 
 
    color: #999; 
 
    font-size: 17px; 
 
    font-family: 'PT Sans', sans-serif; 
 
}
<table> 
 
    <tr> 
 
    <td class="ndLabel" style="position: relative; width: 470px; top:-4px" id="avPurchase03">Average, &euro;:</td> 
 
    <td colspan="2"> 
 
     <input id="lpcfIn02Id" class="ndInbox" type="text" value="" /> 
 
    </td> 
 
    </tr> 
 
    <tr> 
 
    <td class="ndLabel" style="position: relative; width: 470px; top:-4px" id="avNumber03">Budget, &euro;:</td> 
 
    <td colspan="2"> 
 
     <input id="lpcfIn03Id" class="ndInbox" type="text" value="" /> 
 
    </td> 
 
    </tr> 
 
</table>

私はblurを使用して不完全なjQueryの実装を書いていますが、目的の機能が得られませんでした。上記の写真に示されている私の要件は有効ですか?

ありがとうございます。

jsFiddle

UPDATE: 私も次のフィールドにいる場合、ユーザータブを意味し、入力ボックスの外側をクリックして。

+0

あなたは私たちすべてが、文字列操作であなたの試みを示してきました。それは問題なのですよね? – isherwood

答えて

1

ちょうど2桁の適切な小数点に入力された値を変換したいと思うようです。あなたは以下に示すsee a live example hereできると

<input class='make-decimal' /> 
<script> 
    $(function(){ 
     // When an input loses focus... 
     $('.make-decimal').blur(function(){ 
      // Take your value, parse it as a number and output it 
      // to exactly two digits 
      $(this).val(Number($(this).val()).toFixed(2)) 
     }) 
    }); 
</script> 

enter image description here

あなたはtoFixed()機能を使用して、それをフォーマット、現在の値を解析するNumber()機能を使って、それを達成するために、次のと使用することができますさて、あなたの数字の間にスペースを追加することで、おそらくRegular Expressionの魔法を使って以下のように扱うことができます:

と以下に示すことができ

enter image description here

+0

ありがとう、それは素晴らしいですが、それでも3桁の間隔です。 – reshad

+1

私はこの問題に対処するために私の応答を更新しました。希望を助けてくれるでしょう:) –

+0

はい!これは私が必要としていたものです – reshad

関連する問題