文本对齐中断jQuery

文本对齐中断jQuery,jquery,css,Jquery,Css,我正试图为我的几个div编写一个覆盖,以防止用户在不执行以前的任务的情况下进行远程访问。我有覆盖工作和消息显示,但当我尝试和中心的消息时,问题就出现了 我的jQuery看起来像这样 $("<div>You have to complete your previous tasks before you can move on.</div>").css({ position: "absolute", width: "100%", height: "10

我正试图为我的几个div编写一个覆盖,以防止用户在不执行以前的任务的情况下进行远程访问。我有覆盖工作和消息显示,但当我尝试和中心的消息时,问题就出现了

我的jQuery看起来像这样

$("<div>You have to complete your previous tasks before you can move on.</div>").css({
    position: "absolute",
    width: "100%",
    height: "100%",
    top: 0,
    left: 0,
    background: "rgba(0,0,0,0.3)"
}).appendTo($(".disabled-box").css("position", "relative"));
在那里,它中断并抛出错误消息

SyntaxError: Unexpected token '-'
知道为什么会发生这种情况吗?

添加如下内容:

$("<div>You have to complete your previous tasks before you can move on.</div>").css({
    position: "absolute",
    width: "100%",
    height: "100%",
    top: 0,
    "text-align": "center",
    left: 0,
    background: "rgba(0,0,0,0.3)"
}).appendTo($(".disabled-box").css("position", "relative"));
$(“您必须完成以前的任务才能继续。”).css({
位置:“绝对”,
宽度:“100%”,
高度:“100%”,
排名:0,
“文本对齐”:“居中”,
左:0,,
背景:“rgba(0,0,0,0.3)”
}).appendTo($(“.disabled box”).css(“位置”、“相对”);
您可以这样做

textAlign: "center"
但是

这也行。这取决于你


我只是想保持一致。

您需要将代码更改为:

$("<div>You have to complete your previous tasks before you can move on.</div>").css({
    position: "absolute",
    width: "100%",
    height: "100%",
    top: 0,
    left: 0,
    background: "rgba(0,0,0,0.3)",
    textAlign: 'center'
}).appendTo($(".disabled-box").css("position", "relative"));
$(“您必须完成以前的任务才能继续。”).css({
位置:“绝对”,
宽度:“100%”,
高度:“100%”,
排名:0,
左:0,,
背景:“rgba(0,0,0,0.3)”,
textAlign:“中心”
}).appendTo($(“.disabled box”).css(“位置”、“相对”);
对于样式,当使用JavaScript引用样式时,破折号总是替换为。

尝试
定位:“固定”
和样式
边距
我一直在显示自己的消息。我想你的对话框在屏幕上是静态的


不要把代码浪费在JQuery上,我最好为你的部门建立一个类中心

.center{margin:0 0;width:100%;height:100%;top:0px;left:0px;position:fixed;background-color:#FAFAFA;overflow:hidden;opacity:0.9;z-index:99;}


希望有帮助。

我试过了,然后它说有非法的字符串或中心。我只是做了编辑,因为我忘记了逗号,你试过了吗?使用驼峰大小写:
textAlign:“center”、
或引号内的wrap text align键这不是重复的,因为他们在那里使用的文本对齐在这里不起作用。这是重复的。有很多答案,有很多可能的方法。我相信他们会成功的。如果你正在寻找一个不同的答案(不管是什么…),就现有的问题展开悬赏是最好的选择。非常感谢!我知道会有这样的事情发生,但我无法确定!
$("<div>You have to complete your previous tasks before you can move on.</div>").css({
    position: "absolute",
    width: "100%",
    height: "100%",
    top: 0,
    left: 0,
    background: "rgba(0,0,0,0.3)",
    textAlign: 'center'
}).appendTo($(".disabled-box").css("position", "relative"));
.center{margin:0 0;width:100%;height:100%;top:0px;left:0px;position:fixed;background-color:#FAFAFA;overflow:hidden;opacity:0.9;z-index:99;}