简体   繁体   English

为什么这个jQuery .css()不起作用?

[英]Why does this jQuery .css() not work?

I have this javascript to center a span in a div : 我有这个JavaScript来居中span在一个div

var winWidth = $(window).width();
var winHeight = $(window).height();
var positionLeft = (winWidth/2) - 62;
var positionTop = (winHeight/2) - 32;

$('#centerMessage').ccs("position","absolute");
$('#centerMessage').ccs("top",positionTop);
$('#centerMessage').ccs("left",positionLeft);

I keep getting the error that the object does not have the method css. 我不断收到对象没有方法css的错误。 Any idea what is wrong? 知道什么是错的吗?

All the HTML and CSS are at this fiddle (I am getting the exact same error there: http://jsfiddle.net/chromedude/s6WQD/ 所有的HTML和CSS都在这个小提琴(我在那里得到完全相同的错误: http//jsfiddle.net/chromedude/s6WQD/

you are using ccs not css in your code 您在代码中使用ccs而不是css

$('#centerMessage').css("position","absolute");
$('#centerMessage').css("top",positionTop + 'px');  // add unit also
$('#centerMessage').css("left",positionLeft + 'px');

您还应该为您的值添加单位:

$('#centerMessage').css("top",positionTop + "px");

你需要使用.css ,而不是.ccs

你确定你的页面中包含了jquery吗?

.ccs => .css

Try: 尝试:

$('#centerMessage').css("top",positionTop + "px");
$('#centerMessage').css("left",positionLeft + "px");

错误的财产:

.ccs - > .css

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM