document.write(<span style='white-space:pre'>"+string+"</span>");
string中的空格能原本输出
string中的空格能原本输出
2016-03-03
function openWindow(){
var opencheck = confirm("Are you sure to open a new web?");
if(opencheck=true){
var web_addr=prompt("Please enter the site","http://www.imooc.com/");
window.open(web_addr,'_blank','width=400,height=500');
}
}
var opencheck = confirm("Are you sure to open a new web?");
if(opencheck=true){
var web_addr=prompt("Please enter the site","http://www.imooc.com/");
window.open(web_addr,'_blank','width=400,height=500');
}
}
最赞回答 / 灿烂满天星
不想要空格的话,就不能分开写在<head>和<body>里面,这不是用两个document来输出的问题,如果document.write("I love");document.write("javascript");都写在<head>里面,即使是用了两个document,也是没有空格的。
2016-03-03
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8";>
<title>reshen</title>
</head>
<body>
<p id="p1">1111</p>
<p id="p2">2222</p>
<script type="text/javascript">
document.write("hello");
document.getElementById("p1").style.color="blue";
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8";>
<title>reshen</title>
</head>
<body>
<p id="p1">1111</p>
<p id="p2">2222</p>
<script type="text/javascript">
document.write("hello");
document.getElementById("p1").style.color="blue";
</script>
</body>
</html>
2016-03-02
var openWindow = function(){
if(confirm("是否打开新窗口?")){
window.open("http://www.baidu.com","_blank","width=400,height=500,toolbar=no,menubar=no");
}
}
if(confirm("是否打开新窗口?")){
window.open("http://www.baidu.com","_blank","width=400,height=500,toolbar=no,menubar=no");
}
}
格式:Object.style.property=new style;
例子:mychar.style.color="red";
例子:mychar.style.color="red";
2016-03-02
<script type="text/javascript">
function Wopen(){
window.open('http://www.imooc.com','_blank','width=600','height=400','top=100','left=0')
}
</script>
function Wopen(){
window.open('http://www.imooc.com','_blank','width=600','height=400','top=100','left=0')
}
</script>
2016-03-02
<script type="text/javascript">
var score =80; //score变量存储成绩,初值为80
if(score>=60)
{
document.write("很棒,成绩及格了。");
}
else
{
document.write("加油,成绩不及格。");
}
</script>
var score =80; //score变量存储成绩,初值为80
if(score>=60)
{
document.write("很棒,成绩及格了。");
}
else
{
document.write("加油,成绩不及格。");
}
</script>
2016-03-02