2016-06-02 2 views
0

확인을 위해 textarea 필드에 required 속성이 있는지 확인하고 싶습니다. 사용자가 제출을 클릭하면 로딩 이미지가 팝업됩니다. 유효성 검사 메시지가 표시된 후에 이미지가 숨겨 졌는지 확인하려고합니다. 아래는Textarea 필드에 필수 항목이 있는지 확인하십시오. 속성

<textarea id="title" style="width:100%; name="title" required></textarea> 

jQuery를

$("#submit").on("click",function() { 
    $("#loading").css("display", "block"); //display the image 
    return true; 
}); 

내가 required가 로딩 이미지가 표시되지 않습니다, true 있는지 확인하는 방법을 알고있다

HTML, 코드입니다. 아래 에서처럼 노력했지만 결과는 실패했습니다.

$("#submit").on("click",function() { 
    $("#loading").css("display", "block"); 
    return true; 

    if ($("#title").prop("required",true)) { 
     $("#loading").css("display", "none"); 
    } 
}); 

답변

1
<script type="text/javascript"> 
    $("#submit").on("click",function() { 
    if ($("#title").val() != '') { 
     $("#loading").css("display", "none"); 
    } 
    else { 
     $("#loading").css("display", "block"); 
     setTimeout(function(){ $('#loading').fadeOut() }, 5000); 
    } 

}); 
</script> 

이미지가 표시되어야하는 시간 (초). 나는 5 초 동안 지켰다.

+0

** ** 도움에 감사드립니다. 내가 원했던 것처럼 – Amran

+0

환영합니다. @ 암란 –

1

귀하는 updating the required property instead get it using prop(''required)입니다. required 속성은 다음 !true가 발생할 수있는 경우 경우에 여기

$("#submit").on("click",function() { 
    $("#loading").toggle(!$("#title").prop("required")); 
}); 

.toggle(!true) : required으로

if ($("#title").prop("required")) { 
    $("#loading").css("display", "none"); 
} 
0

.toggle(condition)의 조합으로 게터 .prop() (하나의 인자)를 사용할 수있는 속성입니다 요소를 숨기려면.

관련 문제