변수값 콤마 부여하기 채택완료

3552902211_1637136252.8388.png

 

아래 코드를 사용해서 위의 것을 구현했습니다.

위에 30,000이런식으로 넣고 싶은데

변환하는 숫자에는 콤마가 안나타나더라구요.

혹시 어떻게 하면 될까욤?

 

Copy
<!-- Range Slider CSS -->

<link rel="stylesheet" href="../css/pay_style.css">

<!--Only for demo purpose - no need to add.-->

<link rel="stylesheet" href="../css/pay_demo.css" />

 

<section>

    <div class="rt-container">

        <div class="col-rt-12">

            <div class="Scriptcontent">

 

                <!-- Range Slider HTML -->

                <div slider id="slider-distance">

                    <div>

                        <div inverse-left style="width:70%;"></div>

                        <div inverse-right style="width:70%;"></div>

                        <div range style="left:30%;right:40%;"></div>

                        <span thumb style="left:30%;"></span>

                        <span thumb style="left:60%;"></span>

                        <div sign style="left:30%;">

                            <span id="value" class="min_value">30000</span>

                        </div>

                        <div sign style="left:60%;">

                            <span id="value" class="max_value">60000</span>

                        </div>

                    </div>

                    <input type="range" id="min_input" tabindex="0" value="30000" max="100000" min="0" step="1" oninput="

  this.value=Math.min(this.value,this.parentNode.childNodes[5].value-1);

  var value=(100/(parseInt(this.max)-parseInt(this.min)))*parseInt(this.value)-(100/(parseInt(this.max)-parseInt(this.min)))*parseInt(this.min);

  var children = this.parentNode.childNodes[1].childNodes;

  children[1].style.width=value+'%';

  children[5].style.left=value+'%';

  children[7].style.left=value+'%';children[11].style.left=value+'%';

  children[11].childNodes[1].innerHTML=this.value;" />

 

                    <input type="range" id="max_input" tabindex="0" value="60000" max="100000" min="0" step="1" oninput="

  this.value=Math.max(this.value,this.parentNode.childNodes[3].value-(-1));

  var value=(100/(parseInt(this.max)-parseInt(this.min)))*parseInt(this.value)-(100/(parseInt(this.max)-parseInt(this.min)))*parseInt(this.min);

  var children = this.parentNode.childNodes[1].childNodes;

  children[3].style.width=(100-value)+'%';

  children[5].style.right=(100-value)+'%';

  children[9].style.left=value+'%';children[13].style.left=value+'%';

  children[13].childNodes[1].innerHTML=this.value;" />

                </div>

                <!-- End Range Slider HTML -->




 

            </div>

        </div>

    </div>

</section>


 

<script>

    function numberWithCommas(x) {

        return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

    }

 

    var pay_value = $('#value').html();

 

    pay_value = numberWithCommas(pay_value);

 

    $('#value').html(pay_value);


 

</script>

<!-- Analytics -->

 

 

답변 1개

채택된 답변
+20 포인트

Copy
<div sign style="left:30%;">
    <span id="value1" class="min_value">30000</span>
</div>
<div sign style="left:60%;">
    <span id="value2" class="max_value">60000</span>
</div>

 

Copy
<script>
function numberWithCommas(x) {
  return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

$('#value1').html(numberWithCommas($('#value1').html()));
$('#value2').html(numberWithCommas($('#value2').html()));
</script>
로그인 후 평가할 수 있습니다

답변에 대한 댓글 3개

일단 붙긴하는데 저 슬라이더를 움직여서 숫자가 변경되면 콤마가 사라집니다ㅠ
oninput부분에 .innerHTML=this.value 에서
.innerHTML=numberWithCommas(this.value)
으로 변경하세요


그리고... oniput에있는건 함수로 빼주세요 ㅠㅠ
함수로.. 제가 초보라서 그런데 어떻게 정리할 수 있을까요?
함수로 빼보려고 시도했는데 그럼 구동이 안되더라구요

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인
🐛 버그신고