Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript window.location不带条件执行_Javascript_Jquery_Html - Fatal编程技术网

Javascript window.location不带条件执行

Javascript window.location不带条件执行,javascript,jquery,html,Javascript,Jquery,Html,JavaScript p{ display: inline-block; } input[type="checkbox"]:disabled + label{ opacity: .5; } .faded{ color: grey; opacity: .5; } <p>Links should go to their respective locations upon checkbox selection</p> <br> <a

JavaScript

p{
    display: inline-block;
}
input[type="checkbox"]:disabled + label{
    opacity: .5;
}
.faded{ color: grey;
    opacity: .5;
}

<p>Links should go to their respective locations upon checkbox selection</p>
<br>

<a href="www.google.com" class="social" id="social">Link one</a> 
<a href="www.cnn.com" class="social" id="social">Link two</a> 
<a href="www.facebook.com" class="social" id="social">Link three</a> 

<div class="know-your-role">
    <div id="checkwrapper">
        <form method="POST" action="">
            <p>Are you a</p>
            <input type="checkbox" id="check-1"  class="checkchoice student" value="1"><label for="check-1" class="choice student tooltip" title="Student">Student</label>
            <p>or</p>
            <input type="checkbox" id="check-2" class="checkchoice teach" value="2"><label for="check-2" class="choice teach tooltip" style="padding-right: 20px;" title="Teacher">Teacher</label>
            <p>?</p>
        </form>
    </div>
    <div class="style-select type">
        <input type="text" placeholder="What year" />
    </div>
    <p class="faded">       
     "What year" input should only appear when student is selected'
    </p>
</div>
正确的语法是
val()
而不是
va()

-----------------------编辑---------------------------------------


现在按照OP-ask工作

可能需要将所有代码放在$(function(){})中@我以前尝试过,但仍然无法执行window.location。但我不知道你所说的“ID必须是唯一的”是什么意思。什么id?
id=“social”
你在所有
a
元素中都有这个id属性,id属性在所有html页面中都应该是唯一的哦,所以你说的是$('social')。每个(函数(){//do stuff}?我无论如何都不是jquery专业人士,所以请原谅我的n00bie nessNo你不必做
$('social')。每个(函数(){}
由于ID是唯一的它与$(“#社交”)相同,请检查小提琴,看看您的代码是否工作正常
p{
    display: inline-block;
}
input[type="checkbox"]:disabled + label{
    opacity: .5;
}
.faded{ color: grey;
    opacity: .5;
}

<p>Links should go to their respective locations upon checkbox selection</p>
<br>

<a href="www.google.com" class="social" id="social">Link one</a> 
<a href="www.cnn.com" class="social" id="social">Link two</a> 
<a href="www.facebook.com" class="social" id="social">Link three</a> 

<div class="know-your-role">
    <div id="checkwrapper">
        <form method="POST" action="">
            <p>Are you a</p>
            <input type="checkbox" id="check-1"  class="checkchoice student" value="1"><label for="check-1" class="choice student tooltip" title="Student">Student</label>
            <p>or</p>
            <input type="checkbox" id="check-2" class="checkchoice teach" value="2"><label for="check-2" class="choice teach tooltip" style="padding-right: 20px;" title="Teacher">Teacher</label>
            <p>?</p>
        </form>
    </div>
    <div class="style-select type">
        <input type="text" placeholder="What year" />
    </div>
    <p class="faded">       
     "What year" input should only appear when student is selected'
    </p>
</div>
$('.type').hide(); 
$(".know-your-role").hide();


$(".social").click(function(e){
    e.preventDefault();
    var href = $(this).attr('href');
    $(".wizard").hide();
    $('.know-your-role').show('fast');
    var $student = $('input:checkbox.student');
    var $teach = $('input:checkbox.teach');

    if($student.is(':checked') & $(".year").va() != ""){
        window.location.href = href;
    }else if ($teach.is(':checked')){
        window.location.href = href;
    }
});

$(function(){
    $('#check-1').change(function() {
        $('#checkwrapper').hide();
        $('.type').css('width','110px')
        $('.type').show();
    });
});

$('input:checkbox.checkchoice').click(function(){
    var $inputs = $('input:checkbox.checkchoice');
    if($(this).is(':checked')){
        $inputs.not(this).prop('disabled',true);
    }else{
        $inputs.prop('disabled',false);
    }
});
<a href="http://www.google.com" class="social">Link one</a> 
<a href="http://www.cnn.com" class="social">Link two</a> 
<a href="http://www.facebook.com" class="social">Link three</a> 
if($student.is(':checked') & $(".year").va() != ""){