코드 정리 도와주실분 계신가요?

코드 정리 도와주실분 계신가요?

QA

코드 정리 도와주실분 계신가요?

답변 1

본문

수정전 코드를 수정후 코드처럼 따로 뺐는데 

수정후 코드는 제대로 구현이 안되더라구요.

그래서 정리를 어떻게 해야하는지 모르겠습니다. 

혹시 알려주실 분 계신가요ㅠ

 


 
// 수정전
<input type="range" id="min_input" tabindex="0" value="600000" max="2000000" min="1000" step="1000" 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=numberWithCommas(this.value);" />
                    <input type="range" id="max_input" tabindex="0" value="1200000" max="2000000" min="1000" step="1000" 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=numberWithCommas(this.value);" />
 
 
 
// 수정후
 
<input type="range" id="min_input" tabindex="0" value="600000" max="2000000" min="1000" step="1000" oninput="rangeOne()" />
 
<script>
    function rangeOne() {
        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=numberWithCommas(this.value);
    }
</script>
 

이 질문에 댓글 쓰기 :

답변 1

함수에 데이터를 안넘겼으니 함수에서 처리가 안됩니다

oninput = "rangeOne(this)";

이렇게하고

function reangeOne(item) 파라미터를 지정해주고

해당 함수안에있는 this를 item으로 모두 변경하세요

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
  • 질문이 없습니다.
전체 0
© SIRSOFT
현재 페이지 제일 처음으로