변수를 js 함수로 전달할 수 있습니까? 코드를 참조하십시오.JavaScript 함수에 변수를 전달하는 방법은 무엇입니까?
function checkStartPrice(){
if ($('#StartingPrice')[0].value.length == 0){
alert("The 'Starting Price' cannot be left empty!");
return false;
} else {
var BuyItNowPrice = parseFloat($('#BuyItNowPrice').val());
var StartingPrice = parseFloat($('#StartingPrice').val());
var Reserve = parseFloat($('#Reserve').val());
if((BuyItNowPrice <= StartingPrice) && (StartingPrice > 0)){
alert("The 'Buy It Now' price must be higher...");
return false;
}
if((Reserve <= StartingPrice) && (StartingPrice > 0)){
alert("Your 'Reserve Price' must be higher...");
return false;
}
return true;
}
}
나는 var BuyItNowPrice = parseFloat($('#BuyItNowPrice').val());
등을하고 함수 외부를 배치, 다음에 그들에게 전화하고 싶습니다
을 이유는 나는 이러한 기능의 3이이 세 변수 때문에 (BuyItNowPrice
, StartingPrice
, Reserve
)는 9 회, 각 기능에서 3 회 반복된다.
이 방법이 있습니까?
어떤 도움
은 크게, 감사
왜 변수를 전역 범위로 이동하지 않습니까? – reporter