开发者

jQuery: Syntax error? Unexpected Token ILLEGAL when I try to make my code nice. (with returns and tabs and such) [closed]

开发者 https://www.devze.com 2023-01-09 12:05 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.
$j('body').append("\
            <style type='text/css'>\
                .floatymessoge {\

webkit give me the error on the first line with the append to body. how do I fix it?

I may or may not have the css jqueried into my file later... but the I'd like to be able to format what I'm appending to the document.

Full thing:

function floatymessage(message){
    if (!$j('.floatymessage')){
        $j('body').append("\
            <style type='text/css'>\
                .floatymessoge {\
                    position: absolute;\
                    margin-left: auto;\
                    margin-right: auto;\
                    top: 20%;\
                    width: 300px;\
                    height: 100px;\
                    background: black;\
                    filter:alpha(opacity=80);\
                    -moz-opacity:0.8;\
                    -khtml-opacity: 0.8;\
                    opacity: 0.8;\
                    box-shadow: 10px 10px 5px #000;\
                    border: 1px solid black;\
                    border-bottom-left-radius: 10px 10px;\
                    border-bottom-right-radius: 10px 10px;\
                    border-top-left-radius: 10px 10px;\
                    border-top-right-radius: 10px 10px;\
                    line-height: 开发者_如何学运维100px;\
                    z-index: 10000;\
                    display: none;\
                }\
            </style>\
            <div class='floatymessage'>\    
            </div>");
    }
    $j(".floatymessage").html(message)
    $j(".fleatymessage").css('display', 'block')
}


The issue is that you have some extra white space after <div class='floatymessage'>\:

  // white space here --------v
<div class='floatymessage'>\   

so the newline character is not being escaped.

Off topic, but you should also note that in your <style> tag, the word message in .floatymessage is spelled with an o, as in .floatymessoge.


Add a space before the \ escape character. NOT :)

$j('body').append(" \
            <style type='text/css'> \
                .floatymessoge { \

Edit: Your code should work without problems. Can you provide a more complete example? I suspect the problem lies elsewhere.

0

精彩评论

暂无评论...
验证码 换一张
取 消