전체 공개 : 저는 java/jquery 초보자입니다. 그러나이 은 쉬운 솔루션의 문제점과 같습니다.처럼 보입니다. 나는 주변을 둘러 보았고 비슷한 상황을 발견 할 수 없었지만, 이미 이것에 관한 글이 있으면 알려줘.확인란의 수를 기준으로 텍스트 필드를 변경하십시오.
제품 체크리스트와 할인 코드 상자가있는 양식을 만들었습니다. 제출을 클릭하면 내가 일을 일을하고 싶습니다 방법 : 어떤 4를 클릭하면
- 당신이 3 이하 중 하나를 클릭하면 더 할인
- 을 얻을 적용 "할인 1"
- 당신이 만약 어떤 5를 클릭, 당신이 어떤 6을 클릭하면 "할인 2"
- , 내가 경고 상자와 함께 작동하도록 왔
"할인 3"적용 적용,하지만 난 다른 비트를 필요로처럼 보인다 텍스트 상자의 값을 할인으로 변경하는 코드?
도움 주셔서 감사합니다.
function check(){
count = 0;
for(x=0; x<document.signup.getElementsByClassName("styled").length; x++){
if(document.signup.getElementsByClassName("styled")[x].checked==true){
count++
}
}
if(count<3){
alert("No Discount");
}
else if(count==3){
alert("Discount1");
}
else if(count==4){
alert("Discount2");
}
else if(count==5){
alert("Discount3");
}
else if(count==6){
alert("Discount4");
}
}
<form name="signup" id="form1" method="post" action="">
<input type="checkbox" id="product1" name="product_id[]" value="1" class="styled">
<input type="checkbox" id="product2" name="product_id[] "value="3" class="styled">
<input type="checkbox" id="product3" name="product_id[]" value="2" class="styled">
<input type="checkbox" id="product4" name="product_id[]" value="4" class="styled">
<input type="checkbox" id="product5" name="product_id[]" value="44" class="styled">
<input type="checkbox" id="product6" name="product_id[]" value="45" class="styled">
<input type="text" name="coupon" id="f_coupon" value="" size="15" />
<input type="button" name="Button" value="Click Me" onclick="check()" />
-j :
는 여기에 지금까지 가지고있는 옷을 벗었 코드입니다.
나는 아마 클라이언트가 가짜 할인을 만들지 못하도록 서버 측에서 이것을 처리 할 것이다. 내가 말하고자하는 것을 무시하면 [jQuery의 형식 메소드] (http://api.jquery.com/category/forms/), 특히'$ (form) .submit()'을 살펴볼 것이다. '$ (textInput) .val (newValue)'와 같은 것을 사용하여 필드를 설정할 수 있습니다. – sczizzo
원하는 (요청한) 효과를 얻기 위해 코드를 수정했습니다. http://jsfiddle.net/JkjUc/이 코드는 사용자 인터페이스에서 빠른 응답을 위해서만 * * * 유일한 검증 메커니즘으로 사용하십시오. –