码迷,mamicode.com
首页 > 其他好文 > 详细

trim问题和显示多个窗口问题

时间:2016-08-17 10:31:32      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

今天在学习JS的过程中遇到了两个问题:

第一:在eclipse的内置浏览器中alert窗口跳不出来,无显示,而在外置浏览器中就可以正常显示,结果其原因是:eclipse的内置浏览器不支持trim(),把trim删掉即可。

有trim的代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>菜鸟教程</title>
</head>
<head>
<script>
function setCookie(cname,cvalue,exdays){
var d = new Date();
d.setTime(d.getTime()+(exdays*24*60*60*1000));
var expires = "expires="+d.toGMTString();
document.cookie = cname+"="+cvalue+"; "+expires;
}
function getCookie(cname){
var name = cname + "=";
var ca = document.cookie.split(‘;‘);
for(var i=0; i<ca.length; i++) {
// alert("*"+ca[i]+"*");
// ca[i] = "test";
var c = ca[i].trim();
// alert("*"+c+"*");
// var c = ca[i];
if (c.indexOf(name)==0) return c.substring(name.length,c.length);
}
return "";
}
function checkCookie(){
var user=getCookie("username");
if (user!=""){
alert("Welcome again " + user);
}
else {

user = prompt("Please enter your name:","");
if (user!="" && user!=null){
setCookie("username",user,30);
}
}
}
</script>
</head>

<body onload="checkCookie()"></body>
</html>



无trim的代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>菜鸟教程</title>
</head>
<head>
<script>
function setCookie(cname,cvalue,exdays){
var d = new Date();
d.setTime(d.getTime()+(exdays*24*60*60*1000));
var expires = "expires="+d.toGMTString();
document.cookie = cname+"="+cvalue+"; "+expires;
}
function getCookie(cname){
var name = cname + "=";
var ca = document.cookie.split(‘;‘);
for(var i=0; i<ca.length; i++) {
// alert("*"+ca[i]+"*");
// ca[i] = "test";
// var c = ca[i].trim();
// alert("*"+c+"*");
var c = ca[i];
if (c.indexOf(name)==0) return c.substring(name.length,c.length);
}
return "";
}
function checkCookie(){
var user=getCookie("username");
if (user!=""){
alert("Welcome again " + user);
}
else {

user = prompt("Please enter your name:","");
if (user!="" && user!=null){
setCookie("username",user,30);
}
}
}
</script>
</head>

<body onload="checkCookie()"></body>
</html>




第二个问题:显示多个窗口,结果在外置的浏览器中总是显示一个窗口,结果原因是:另一个窗口被屏蔽,解决办法:在浏览器的设置里找到窗口弹出设置,更改为接受所有窗口,即可。


代码如下:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script>
function open_win() {
myWindow=window.open("http://www.w3schools.com/","first");
window.open("http://www.microsoft.com/","second");
}
</script>
</head>
<body>

<form>
<input type="button" value="打开窗口" onclick="open_win()">
</form>

</body>
</html>




第三点:在JSP中测试用alert测试非常好,就跟在C里用printf测试一样!一定要记住alert经常用来测试的功能。

trim问题和显示多个窗口问题

标签:

原文地址:http://www.cnblogs.com/cyy-13/p/5778586.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!