document.write的第一行格式不正确,有时不显示

时间:2016-04-15 09:18:42

标签: javascript html

function getHotel() {  
    var hotel = [ {
        "hotelName":"Sierra Resort Hotel",
        "photoUrl":"../Pictures/caption.jpg",
        "webUrl":"http://www.sierrahakuba.com/",
        "recommended":"y",
        "desc":"Sierra Resort Hotel is Hakuba's largest accommodation facility. Over 60,000m2 of landscaped gardens,mountain stream and natural forest surround our buildings; which are constructed in harmony with the natural surrounds.Sierra resort Hakuba is in the wonderful environment surrounded by the forest of 25acers.",
        "price":"1700HKD"
        }, 
        {
        "hotelName":"Funny Inn Hakuba",
        "photoUrl":"../Pictures/_MG_9357.jpg",
        "webUrl":"http://www.funnyinn.com/original18.html",
        "recommended":"n",
        "desc":"Named ‘Funny Inn’ to reflect the relaxing atmosphere, we offer warm hospitality to those who would like the experience of staying in a genuine Japanese Pension. Voted one of the best hotel in the Hakuba area by Trip Advisor, we hope to be able to offer to you the wonderful fusion of staying in a small six room pension, with European fine dining menus and wines.",
        "price":"500HKD"
        },
        {
        "hotelName":"Hakuba Onsen Ryokan Shiroumaso",
        "photoUrl":"../Pictures/shirouma1.jpg",
        "webUrl":"http://www.shiroumaso.com[enter image description here][1]/english/",
        "recommended":"n",
        "desc":"Resting at the base of Hakuba Happo-one ski area, Shirouma-so is a modern Japanese ryokan (inn) combining both traditional wood and modern Japanese ”Wa” architectural styles, resulting in a creative and beautiful design. From the entrance featuring wooden pillars and beams preserved from the building's agricultural beginnings in the Edo period.",
        "price":"1500HKD"
        }
    ];
    var random=Math.floor((Math.random()*3));
    document.write(random)
    for (var x=0;x<random;x++) {
        document.write('<div style=" background-color: #353536;color:#ED5E11;min-height: 300px;overflow: hidden; padding: 0px;margin: 5px;border-width: thick;border-color:#ED5E11;border-style: solid;>')
        document.write('<br><br>')
        if (hotel[x].recommended=="y") {
            document.write('<p style="font: small-caps bold 1.67em Verdana, Arial, Helvetica, sans-serif;letter-spacing: .2em; text-align: center;"><u>'+"RECOMMENDED"+'</u></p>')
        }
        document.write('<img style=" border-width: medium;border-color:#692F1D;border-style: solid;padding: 2px;width: 400px;margin: 50px 10px 0px 0px;float: right; " alt="'+hotel[x].hotelName+'" src="'+hotel[x].photoUrl+'"></img>')
        document.write('<p style="font: small-caps bold 1.67em Verdana, Arial, Helvetica, sans-serif;letter-spacing: .2em; text-align: center;"><u>'+hotel[x].hotelName+'</u></p>')
        document.write('<p style="font: small-caps bold 1em Verdana, Arial, Helvetica, sans-serif;margin: 5px;"><b>Name: </b>'+ hotel[x].hotelName+'<br><br>'+hotel[x].desc+'<br><br><b>Price: </b>'+hotel[x].price+'<br><br><b>Link: </b><a  href="'+hotel[x].webUrl+'" target="_blank">'+hotel[x].hotelName+'</a><br><br></p>')
        document.write('<a style="font: small-caps bold 1em Verdana, Arial, Helvetica, sans-serif;margin: 5px;" href="Hotel%20Rooms%20%28Hakuba%20Windy%20Lodge%29.html"> Detail</a>')
        document.write('</div>')
    }   
}

每个<div>中的第一行格式不正确。 跳过<img>语句并输入if语句时,if标记不显示,“推荐”格式不正确。

1 个答案:

答案 0 :(得分:0)

关闭此行中的样式引号

document.write('<div style=" background-color: #353536;color:#ED5E11;min-height: 300px;overflow: hidden; padding: 0px;margin: 5px;border-width: thick;border-color:#ED5E11;border-style: solid;">')

function getHotel()
    {  
    var hotel = [
    {
    "hotelName":"Sierra Resort Hotel",
    "photoUrl":"../Pictures/caption.jpg",
    "webUrl":"http://www.sierrahakuba.com/",
    "recommended":"y",
    "desc":"Sierra Resort Hotel is Hakuba's largest accommodation facility. Over 60,000m2 of landscaped gardens,mountain stream and natural forest surround our buildings; which are constructed in harmony with the natural surrounds.Sierra resort Hakuba is in the wonderful environment surrounded by the forest of 25acers.",
    "price":"1700HKD"
    }, 
    {
    "hotelName":"Funny Inn Hakuba",
    "photoUrl":"../Pictures/_MG_9357.jpg",
    "webUrl":"http://www.funnyinn.com/original18.html",
    "recommended":"n",
    "desc":"Named ‘Funny Inn’ to reflect the relaxing atmosphere, we offer warm hospitality to those who would like the experience of staying in a genuine Japanese Pension. Voted one of the best hotel in the Hakuba area by Trip Advisor, we hope to be able to offer to you the wonderful fusion of staying in a small six room pension, with European fine dining menus and wines.",
    "price":"500HKD"
    },
    {
    "hotelName":"Hakuba Onsen Ryokan Shiroumaso",
    "photoUrl":"../Pictures/shirouma1.jpg",
    "webUrl":"http://www.shiroumaso.com[enter image description here][1]/english/",
    "recommended":"n",
    "desc":"Resting at the base of Hakuba Happo-one ski area, Shirouma-so is a modern Japanese ryokan (inn) combining both traditional wood and modern Japanese ”Wa” architectural styles, resulting in a creative and beautiful design. From the entrance featuring wooden pillars and beams preserved from the building's agricultural beginnings in the Edo period.",
    "price":"1500HKD"
    }
];
    var random=Math.floor((Math.random()*3));
    document.write(random)
    for (var x=0;x<random;x++)
    {
        document.write('<div style=" background-color: #353536;color:#ED5E11;min-height: 300px;overflow: hidden; padding: 0px;margin: 5px;border-width: thick;border-color:#ED5E11;border-style: solid;">')
        document.write('<br><br>')
        if (hotel[x].recommended=="y")
        {
        document.write('<p style="font: small-caps bold 1.67em Verdana, Arial, Helvetica, sans-serif;letter-spacing: .2em; text-align: center;"><u>'+"RECOMMENDED"+'</u></p>')
        }
        document.write('<img style=" border-width: medium;border-color:#692F1D;border-style: solid;padding: 2px;width: 400px;margin: 50px 10px 0px 0px;float: right; " alt="'+hotel[x].hotelName+'" src="'+hotel[x].photoUrl+'"></img>')
        document.write('<p style="font: small-caps bold 1.67em Verdana, Arial, Helvetica, sans-serif;letter-spacing: .2em; text-align: center;"><u>'+hotel[x].hotelName+'</u></p>')
        document.write('<p style="font: small-caps bold 1em Verdana, Arial, Helvetica, sans-serif;margin: 5px;"><b>Name: </b>'+ hotel[x].hotelName+'<br><br>'+hotel[x].desc+'<br><br><b>Price: </b>'+hotel[x].price+'<br><br><b>Link: </b><a  href="'+hotel[x].webUrl+'" target="_blank">'+hotel[x].hotelName+'</a><br><br></p>')
        document.write('<a style="font: small-caps bold 1em Verdana, Arial, Helvetica, sans-serif;margin: 5px;" href="Hotel%20Rooms%20%28Hakuba%20Windy%20Lodge%29.html"> Detail</a>')
        document.write('</div>')
    }   
}
getHotel();