我是Web开发的新手,因此我正在参加Shawn Wildermuth的Pluralsight课程,名为“使用ASP.NET Core RC1,MVC 6,EF7和AngularJS构建Web应用程序”。在他的jQuery模块中,Shawn的这段代码对他而言完美无缺:
var main = $("#main");
main.on("mouseenter", function() {
main.style = "background-color: #888;";
});
main.on("mouseleave", function() {
main.style = "";
});
我在index.html页面上有一个id为“ main”的div,已引用js文件,同一文件中的其他jQuery功能也可以正常工作,但是我无法使这段代码正常工作。我知道这并不重要,但就个人而言。任何建议都是有帮助的。谢谢!
您不能像这样访问style属性。请尝试以下方法:
var main = $("#main");
main.mouseenter(function() {
main.css("background-color", "#888");
});
main.mouseleave(function() {
main.css("background-color", "none");
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句