[ jquery ] 소숫점 콤마 동시사용 플러그인 > javascript&jQuery

본문 바로가기
사이트 내 전체검색

javascript&jQuery

[ jquery ] 소숫점 콤마 동시사용 플러그인

페이지 정보

작성자 웹지기 댓글 0건 조회 4,835회 작성일 18-09-07 17:41

본문

jQuery Number Plugin

By Sam Sehnert, Custom D 2015

This is a jQuery plugin which allows developers to easily format numbers for display use. Allows users to replace numbers inline in a document, or return a formatted number for other uses.


Requires jQuery 1.6 or greater.


Documentation

See our jQuery Number Format article for more information.


Basic number formatting

The number method takes up to four parameters, but only the first one is required.


Number: The number you want to format.


$.number( 5020.2364 ); // Outputs 5,020

Decimal Places: The number of decimal places you wish to see. Defaults to 0.


$.number( 5020.2364, 2 ); // Outputs: 5,020.24

Decimal Separator: The character(s) to use as a decimal separator. Defaults to '.'.


$.number( 135.8729, 3, ',' ); // Outputs: 135,873

Thousands Separator: The character(s) to use as a thousands separator. Defaults to ','.


$.number( 5020.2364, 1, ',', ' ' ); // Outputs: 5 020,2

Number formatting as-you-type

When targeting a collection of input elements, you can have the number format plugin automatically format the users input based on your format settings.


$('input.number').number( true, 2 );

Passing true to the number parameter, indicates that you want the value of the field or element to be effected, instead of placing the passed number into the field or element. All other parameters are as decribed above.


When the user types, their input will automatically be converted in the correct format. This also attaches .val() hooks which allow you to continue using .val() to set your input elements, and you don't need to worry about handling the formatting.


Automatic paste formatting is also supported.


Writing numbers into an element

$('.selector').number( 1234, 2 ); // Changes the text value of the element matching selector to the formatted number.

Formatting numbers within a collection of elements

Assuming we have the following structure:


<p>

  <span class="number">1025.8702</span>

  <span class="number">18023</span>

  <span class="number">982.3</span>

  <span class="number">.346323</span>

</p>

We can use this JavaScript:


// the 'true' signals we should read and replace the text contents of the target element.

$('span.number').number( true, 2 )

And come away with this result:


<p>

  <span class="number">1,025.87</span>

  <span class="number">18,023.00</span>

  <span class="number">982.30</span>

  <span class="number">0.35</span>

</p>


LICENSE.txt


추천0 비추천0

댓글목록

등록된 댓글이 없습니다.

Total 63건 4 페이지
  • 18 [ jquery ] 강좌 및 동영상
  • jQuery 시리즈 강좌 리스트[jQuery강좌] 1. 웹 개발자를 위한 jQuery 기본이해[jQuery강좌] 2. jQuery를 이용한 HTML DOM 접근 - 기본 셀렉터 (1)[jQuery강좌] 3. jQuery를 이용한 HTML DOM 접근 - 기본 셀렉터 (2)[jQuery강좌] 4. jQuery Selector - 속성(Attribute)[jQuery강좌] 5. jQuery Selector - DOM 계층(Hierarchy)을 이용한 요소 접근 (1)[jQuery강좌] 6. jQuer...
  • 웹지기 09-27 1898 0 0 댓글 0
  • 15 [ jquery ] jquery 기본 명령어
  • [code].appendTo() ==&gt; 1.새로운 요소를 타겟(target)에 해당하는 요소 마지막에 추가합니다. $("span").appendTo("#foo");.append() ==&gt; 2.last() ==&gt; 7.siblings() ==&gt; 8.prevAl!l() ==&gt; 11.prev() ==&gt; 12.prevUntil() ==&gt; 13.parentsUntil() ...
  • 웹지기 09-30 2670 0 0 댓글 0
  • 14 [ javascript ] 현재시간 실시간으로 보기
  • [code] &lt;script type="text/javascript"&gt;function printTime() { var clock = document.getElementById("clock"); var now = new Date(); var ampm; if (now.getHours() &gt;= 12) { ampm = "PM"; } else { ampm = ...
  • 웹지기 09-28 2600 0 0 댓글 0
  • 11 [ javascript ] 쿠키 셋팅 추출 삭제
  • [code]&lt;script&gt;//쿠키 불러내기function getCookie( cookieName ){ var search = cookieName + "="; var cookie = document.cookie; // 현재 쿠키가 존재할 경우 if( cookie.length &gt; 0 ){ // 해당 쿠키명이 존재하는지 검색한 후 존재하면 위치를 리턴. startIndex = cookie.indexOf( cookieName ); // 만...
  • 웹지기 10-01 1688 0 0 댓글 0
  • 열람중 [ jquery ] 소숫점 콤마 동시사용 플러그인
  • jQuery Number Plugin By Sam Sehnert, Custom D 2015 This is a jQuery plugin which allows developers to easily format numbers for display use. Allows users to replace numbers inline in a document, or return a formatted number for other uses. Requires jQuery 1.6 or greater. ...
  • 웹지기 09-07 4836 0 0 댓글 0
  • 6 [ javascript ] 논리 연산자 활용 (삼항연산자의 역할)
  • var day = day_time || day_day || 31; 위의 내용을 풀이하면 day 변수에 값을 넣을 때 day_time 값이 존재하면 day_time 값을 day에 대입한다. day_time값이 없고 day_day에 값이 존재하면 day_day 값을 day에 대입한다. day_time 값이 없고 day_day 값도 없다면 31이라는 값을 day에 대입한다. 이는 삼항 연산자 처럼 사용할 수 있어서 편리하다. functio num(a) { b = a || 29; } 이...
  • 웹지기 11-19 1035 0 0 댓글 0
  • 5 [ javascript ] 동일 연산자와 일치 연산자
  • 동일 연산자 ( == ) 값을 비교해 보자면 null == undefined // -&gt; true 1 == "1" // -&gt; true true == 1 // -&gt; true "0xff" == 255 // -&gt; true (new String("a")) == "a" // -&gt; true (new Number(2)) == 2 // -&gt; tr...
  • 웹지기 11-19 1062 0 0 댓글 0
  • 4 [ javascript ] 변수 명명 규칙, 표기법
  • 캐멀 표기법(로어 캐멀 표기법) newName createLifeGame 파스칼 표기법(어퍼 캐멀 표기법) NewName CreateLifeGame 밑줄 표기법(스네이크 표기법) new_name create_life_game 변수 이름을 지을 때 일반적으로 사용하는 표기법 - 캐멀 표기법, 밑줄표기법으로 변수의 의미를 파악할 수 있게 명명 - 기본적으로 영어로 사용 - 루프 카운터 변수는 i, j, k 등을 사용 -...
  • 웹지기 06-04 2484 0 0 댓글 0
게시물 검색

회원로그인

접속자집계

오늘
6,274
어제
29,471
최대
33,828
전체
8,504,815

그누보드5
Copyright © funyphp.com. All rights reserved.