已采纳回答 / 林青羽
这个和文件的加载顺序有关,放在head里面会先加载js,后加载dom,这样在还没有dom元素的时候获取元素会失败,所以会不起作用,所以一般放在</body>的前面比较妥当,当然有些特殊情况需要放在head里面
2015-11-24
function rec(){
var mymessage=confirm("喜欢看宫斗戏吗?");
if(mymessage==true)
{
document.write("你是女士!");
}
else
{
document.write("你是男士!");
}
}
var mymessage=confirm("喜欢看宫斗戏吗?");
if(mymessage==true)
{
document.write("你是女士!");
}
else
{
document.write("你是男士!");
}
}
2015-11-24
例如:打开http://www.imooc.com网站,大小为300px * 200px,无菜单,无工具栏,无状态栏,有滚动条窗口:
<script type="text/javascript"> window.open('http://www.imooc.com','_blank','width=300,height=200,menubar=no,toolbar=no, status=no,scrollbars=yes')
</script>
<script type="text/javascript"> window.open('http://www.imooc.com','_blank','width=300,height=200,menubar=no,toolbar=no, status=no,scrollbars=yes')
</script>
2015-11-24
<script type="text/javascript">
function hidetext()
{
var mychar = document.getElementById("con");
mychar.style.display ="none";
}
function showtext()
{
var mychar = document.getElementById("con");
mychar.style.display ="block";
}
</script>
function hidetext()
{
var mychar = document.getElementById("con");
mychar.style.display ="none";
}
function showtext()
{
var mychar = document.getElementById("con");
mychar.style.display ="block";
}
</script>
2015-11-24
<script type="text/javascript">
var mychar=document.getElementById("con");
document.write("原标题:"+mychar.innerHTML+"<br>"); //输出原h2标签内容
mychar.innerHTML="Hello world!";
document.write("修改后的标题:"+mychar.innerHTML); //输出修改后h2标签内容
</script>
var mychar=document.getElementById("con");
document.write("原标题:"+mychar.innerHTML+"<br>"); //输出原h2标签内容
mychar.innerHTML="Hello world!";
document.write("修改后的标题:"+mychar.innerHTML); //输出修改后h2标签内容
</script>
2015-11-24
function openWindow(){
var cm = confirm("您是确定要打开网页么?");
if(cm=true){ var win = prompt("请输入要打开的网址");
if(win!=null&&win!=""){window.open(win,'_blank','width=400,height=500')
}else{ window.open('http://www.imooc.com','_blank','width=400,height=500)
}
}
}
var cm = confirm("您是确定要打开网页么?");
if(cm=true){ var win = prompt("请输入要打开的网址");
if(win!=null&&win!=""){window.open(win,'_blank','width=400,height=500')
}else{ window.open('http://www.imooc.com','_blank','width=400,height=500)
}
}
}
已采纳回答 / 慕男婶
结果出乱码了,首先把js文件保存成utf-8格式的文件,然后在页面head标签之间加上<meta charset="UTF-8"><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
2015-11-23
<script type="text/javascript">
function contxt() //定义函数
{
alert("哈哈,调用函数了!");
}
</script>
</head>
<body>
<form>
<input type="button" value="点击我" onclick="contxt()" />
</form>
function contxt() //定义函数
{
alert("哈哈,调用函数了!");
}
</script>
</head>
<body>
<form>
<input type="button" value="点击我" onclick="contxt()" />
</form>
2015-11-23