简体   繁体   English

我的JavaScript有什么问题?

[英]Whats wrong with my Javascript?

I have this bit of javascript and php: 我有这段JavaScript和php:

function change(){

var heading = "<?= $heading ?>";
var description = "<?= $description ?>";
var valid = "<?= $valid ?>";
var background = "<?= $background ?>";
alert("hi");
    switch(background){
        case 1:
        document.getElementById('main').style.backgroundImage = "(url"img/bg1.jpg")";
        break;

        case 2:

        break;

        case 3:

        break;

        default:
        break;
    }
}

If I remove the case 1, the line: document.getElementById('main').style.backgroundImage = "(url"img/bg1.jpg")"; 如果删除的情况下如图1所示,行: document.getElementById('main').style.backgroundImage = "(url"img/bg1.jpg")"; the function will work, I'll get the hi alert. 该功能会工作,我会得到喜警报。 But if its in there it doesn't work at all. 但是,如果它在那里它不会在所有的工作。 But I've used that line of code before and its worked, why does it cause this script to stop working? 但是我用的是代码行前和工作过,为什么它会导致这个脚本停止工作?

TIA TIA

尝试将该行替换为:

document.getElementById('main').style.backgroundImage = "url('img/bg1.jpg')";

case 1 should be as below case 1应如下

case 1:
    document.getElementById('main').style.backgroundImage = "url("img/bg1.jpg")";
    break;

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

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