質問

What is wrong with this code?

var myRutabaga = $("rutabaga");
if(myRutabaga.checked){
    document.$("likerutabagas") = "LIKE";
}else{
    document.$("likerutabagas") = "DO NOT LIKE";
}

It will not execute. I need to find the nodevalue too. How can I fix it?

役に立ちましたか?

解決

What is "rutabaga" and "likerutabagas" ... ?

If id try: var myRutabaga = $("#rutabaga");

If class : var myRutabaga = $(".rutabaga");

他のヒント

please make sure proper selection of html DOM. you should use # for ID or . for class or others valid selector.

var myRutabaga = $("#rutabaga")// or use $(".rutabaga");
if(myRutabaga.checked){
    $("#likerutabagas").text("LIKE"); // or use .html("LIKe")
}else{
    $("#likerutabagas").text("DO NOT LIKE"); // or use .html("DO NOT LIKE")
}

now may it works !

If "rutabaga" is the id of an element, you need to use the $("#rutabaga") selector.

If "rutabaga" is a class of an element, you need to use the $(".rutabaga") selector.

Just using the $("rutabaga") selector means that jQuery is looking for a tag name of "rutabaga", which shouldn't exist. :)

You can also use the jQuery .is(":checked") function to test whether the input is checked or not, like so:

if ($("#rutabaga").is(":checked")) {
    $("#likerutabagas").text("Like");
}
else {
    $("#likerutabagas").text("Do Not Like");
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top