2014-11-03 5 views
0

사용중인 슬라이더에 계산 된 기본 수치를 표시하는 솔루션이 필요합니다. 기본 슬라이더 값은 "800"으로 설정됩니다. 계산 된 금액은 "99"로 표시됩니다. 그러나 계산 된 양은 사용자가 슬라이더를 움직일 때까지 표시되지 않습니다. 그런 다음 아무런 문제가 없습니다. 페이지로드시 기본 계산량이 "99"("800"기준)가되도록 설정하려면 어떻게해야합니까?페이지로드시 기본 계산량이 비어 있음

감사합니다.

$(function() { 
 
$("#slider-range-max").slider({ 
 
    range: "100px", 
 
    min: 500, 
 
    max: 1500, 
 
    value: 800, 
 
    slide: function(event, ui) { 
 
    $("#amount").val(ui.value); //ui.value inside the event contains the slider value 
 
    var x=$("#amount").val(); //this way you access slider value anywhere in your code 
 
    var y=1.49; 
 
    var a= Math.round(x*y/12); 
 
    $("#product").html(a); 
 
    } 
 
}); 
 
    $("#amount").val($("#slider-range-max").slider("value")); 
 

 
}); 
 

 

 
</script> 
 

 

 
</head> 
 
<body> 
 

 
<p> 
 

 
<input type="text" id="amount" style="border:0 
 
; font-size: 40px; color:#f6931f; font-weight:bold;"> 
 

 
<label for="amount" style="border:0 
 
; font-size: 10px; color:#f6931f; font-weight:bold; ">/per month</label> 
 

 
</p> 
 
<div id="slider-range-max"></div> 
 
<br/> 
 

 

 
style="border:0; font-size: 40px; color:#f6931f; font-weight:bold;"> 
 

 
$<span id="product"></span> 
 
</p> 
 

 
</body> 
 
</html>

당신은이 작업을 수행 한 후, 함수에 밖으로 당신의 계산을 이동 변수에 기본 값을 이동 할 수

답변

0

: 마법처럼 일했다

function calculateResult(value) { 
    return Math.round(value * 1.49/12); 
} 

$(function() { 
var defaultValue = 800; 
$("#product").html(calculateResult (defaultValue)); 
$("#slider-range-max").slider({ 
    range: "100px", 
    min: 500, 
    max: 1500, 
    value: defaultValue, 
    slide: function(event, ui) { 
    var productValue = calculateResult(ui.value); 
    $("#amount").val(ui.value); //ui.value inside the event contains the slider value 
    $("#product").html(productValue); 
    } 
}); 
    $("#amount").val($("#slider-range-max").slider("value")); 

}); 
+0

! 정말 고마워! – Drew