2017-07-28 20 views
0

这是我的代码。我想成功的表单提交后的重定向页面,它仍然在该网页上,并且用户需要修复错误如何重定向表单提交是否成功,并保留在页面上它的假使用js

<form id="form_1" name="form" action="#" method="POST"> 
    <div class="btn-group" data-toggle="buttons"> 
    <input class="radio_btn" type="radio" name="group1" value="true">Yes 
    <input class="radio_btn" type="radio" name="group1" value="false">No 
    </div> 
    <div class="btn-group" data-toggle="buttons"> 
    <input class="radio_btn" type="radio" name="group2" value="true">Yes 
    <input class="radio_btn" type="radio" name="group2" value="false">No 
    </div> 
    <button type="submit">Submit</button> 
</form> 

<script> 
    var form = document.querySelector('#form_1'); 
    var radioList = form.querySelectorAll('.radio_btn'); 
    form.addEventListener('submit', function() { 
    for (var i = 0, length1 = radioList.length; i < length1; i++) { 
     if (radioList[i].getAttribute('value') == 'false' && radioList[i].checked) { 
     alert("error"); 
     return false; 
     } else { 
     return true; 
     window.location.assign("http://worldlivecricket.com"); 
     } 
    } 
    }); 
</script> 

回答

0

您可以使用jquery

$("#form_1").on("submit",function(e){ 
    if(your validation) { 
     // redirect 
    } else { 
     e.preventDefault(); 
    } 
}); 

这里e.preventDefault();将停止做这样的重新加载页面

相关问题