如果语句问题,请使用JavaScript

时间:2016-08-12 19:46:50

标签: javascript jquery if-statement

使用Javascript进行项目,我无法得到我的其他if语句工作或显示我指定的块。

$(document).ready(function() {
$("form").submit(function(event){

var like = parseInt($("input:radio[name=like]:checked").val());
var building = parseInt($("#building").val());
var language = parseInt($("#language").val());
var clients = parseInt($("#clients").val());
var study = parseInt($("input:radio[name=study]:checked").val());
var successrate = (like + building + language + clients + study);
if(successrate >5 || <10) {
  $("#javaOut").show();
}else if (successrate >10 || successrate <=15) { then
  $("#phpOut").show();
}else {
  $("#designout").show();
  }
event.preventDefault();
});
});

2 个答案:

答案 0 :(得分:0)

通过查看下面的行if(successrate >5 || <10) {中的拼写错误,它应该是if(successrate >5 || successrate <10) {

答案 1 :(得分:0)

$(document).ready(function() {
    $("form").submit(function(event){    
        var like = parseInt($("input:radio[name=like]:checked").val());
        var building = parseInt($("#building").val());
        var language = parseInt($("#language").val());
        var clients = parseInt($("#clients").val());
        var study = parseInt($("input:radio[name=study]:checked").val());
        var successrate = (like + building + language + clients + study);
        if(successrate >5 && successrate <10) { // was successrate >5 ||<10 => syntax error + always true condition
          $("#javaOut").show();
        }else if (successrate >10 && successrate <=15) { //was successrate >10 && successrate <=15 { then => syntax error + always true condition
          $("#phpOut").show();
        }else {
          $("#designout").show();
        }
        event.preventDefault();
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

你有一些语法错误和条件错误

$(document).ready(function() {
    $("form").submit(function(event){    
        var like = parseInt($("input:radio[name=like]:checked").val());
        var building = parseInt($("#building").val());
        var language = parseInt($("#language").val());
        var clients = parseInt($("#clients").val());
        var study = parseInt($("input:radio[name=study]:checked").val());
        var successrate = (like + building + language + clients + study);
        if(successrate >5 && successrate <=10) { // was successrate >5 ||<10 => syntax error + always true condition
          $("#javaOut").show();
        }else if (successrate >10 && successrate <=15) { //was successrate >10 && successrate <=15 { then => syntax error + always true condition
          $("#phpOut").show();
        }else {
          $("#designout").show();
        }
        event.preventDefault();
    });
});