jquery中的意外标识符错误

Nic*_*nto 0 jquery

这个jquery怎么了?

$(function(){
    totalwidth = $(window).width();
    if ( totalwidth < 1295 ){
        $("#maininvite").width(((1295 - totalwidth)x100 / 1295) + 50 +'%');
    }

});
Run Code Online (Sandbox Code Playgroud)

它的目的是进行计算,然后将其添加到已设置的50%宽度.

它在chrome检查中给了我意想不到的标识符

Sus*_* -- 5

看起来这一行是你的问题

x100
Run Code Online (Sandbox Code Playgroud)

应该是

*100
Run Code Online (Sandbox Code Playgroud)

更好地计算值,然后连接到 '%'

$(function(){
    totalwidth = $(window).width();
    if ( totalwidth < 1295 ){
        var newWidth =  (((1295 - totalwidth) * 100)/1295 ) + 50; 
        $("#maininvite").width( newWidth + '%');
    }

});
Run Code Online (Sandbox Code Playgroud)