css不是功能?

时间:2015-02-13 23:46:19

标签: javascript jquery css

我收到了错误

TypeError: "#divID".css is not a function

我不知道该怎么办才能有人帮忙?

$("#buttonID").click(function(){
   console.log(( "#divID" ).css("display") == "none");
   console.log(( "#divID" ).css("display"));
   if($( "#divID" ).css("display") == "none"){
      console.log("showing");
      $("#divID").css("display", "");
   } else {
      console.log("hiding");
      $("#divID").css("display", "none");
   }
   console.log(" ");
});

2 个答案:

答案 0 :(得分:3)

你需要一美元!

console.log($("#divID" ).css("display") == "none");

答案 1 :(得分:1)

你必须在第2行和第3行添加$

$("#buttonID").click(function(){
   console.log($( "#divID" ).css("display") == "none");
   console.log($( "#divID" ).css("display"));
   if($( "#divID" ).css("display") == "none"){
      console.log("showing");
      $("#divID").css("display", "");
   } else {
      console.log("hiding");
      $("#divID").css("display", "none");
   }
   console.log(" ");
});