做个总结
linux服务器上做负载均衡
自己准备的:linux服务器(45.78.20.168),jdk1.7,nginx,redis,tomcat7两个,部署的项目;
1:jdk1.7安装,两个tomcat分别端口8080,8081;部署相同的项目;启动;
http://45.78.20.168:8080/redis3.2/getRedis.action2:安装nginx,添加负载的配置,安装目录下找
/etc/nginx/conf.d/default.conf文件(或/etc/nginx/nginx.conf);策略设置为默认轮询;
upstream www.nimenhaihaoma.com {
server 45.78.20.168:8080;
server 45.78.20.168:8081;
}
server{
listen 80;
server_name www.nimenhaihaoma.com;
location / {
proxy_pass http://www.nimenhaihaoma.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
3:配置session共享,方式很多,这里用的redis的session共享(兼容jdk版本至少1.7):
tomcat的lib包加
commons-pool2-2.0.jar,jedis-2.5.2.jar,tomcat-redis-session-manager1.2.jar;
tomcat配置文件context.xml,在标签<Context>内添加配置:
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" host="localhost" port="6379" database="0" maxInactiveInterval="60" />
4:项目里面区分session的代码:
(1):放session的接口(执行一次);
(2):取session数据(不断刷新),看tomcat打印信息;
5:效果,
http://www.nimenhaihaoma.com/redis3.2/getRedis.action (狂刷session值相同)
posted @
2016-08-17 17:03 魏文甫 阅读(119) |
评论 (0) |
编辑 收藏
项目只是加载spring的几个定时任务,启动服务一直循环加载spring文件,问题的根节点:定时器类里面的service对象采取配置的方式注入,而这个定时器类的构造让我给加上了:
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext*.xml");
myServiceImpl = context.getBean("XXXService");
加上这段为了方便测试,在该类里写main方法测试执行,把调用写到构造里;,spring定时器配置好时间后,此处构造忘了去掉;导致启动tomcat服务一直在加载spring注入文件;
同理,spring注入的方式,在action里同样有这样的效果,构造方法一定注意;
posted @
2015-04-25 11:09 魏文甫 阅读(175) |
评论 (0) |
编辑 收藏
是在build.xml编译的时候,包里有两个类名一样的java文件,我只是做了个备份,忘了改文件后缀,备份的文件也编译了,所以报的这个错
posted @
2014-08-28 20:18 魏文甫 阅读(824) |
评论 (0) |
编辑 收藏
1,添加索引文件中的一条新的索引
Question addQ = new Question();//新添加的一条数据,对象id在索引文件中没有
addQ.setId("999999999");
addQ.setQuestionname("新添加的一条数据名称");
Analyzer sa = new SmartChineseAnalyzer(Version.LUCENE_40);
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_40, sa);
iwc.setOpenMode(OpenMode.APPEND);
IndexWriter writer = null;
try {
Directory dir1 = FSDirectory.open(new File("F:\\temp"));
writer = new IndexWriter(dir1, iwc);
FieldType ft = new FieldType();
ft.setIndexed(true);
ft.setStored(true);
ft.setTokenized(true);
FieldType ft2 = new FieldType();
ft2.setIndexed(true);
ft2.setStored(true);
ft2.setTokenized(false);
Document doc = new Document();
doc.add(new Field("id", addQ.getId(), ft2));
doc.add(new Field("questionname", addQ.getQuestionname(), ft));
writer.addDocument(doc);
writer.close();
} catch (CorruptIndexException e) {
e.printStackTrace();
} catch (LockObtainFailedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
try {
if(writer!=null){
writer.close();
}
if(sa!=null){
sa.close();
}
} catch (CorruptIndexException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}执行完程序后,索引文件中已经添加新的索引数据。2,删除索引文件中的一条新的索引
Question delQ = new Question();//索引文件中有的一条数据,根据对象id删 delQ.setId("1111111"); delQ.setQuestionname("要删除的一条数据"); IndexWriter writer = null;
Analyzer sa = new SmartChineseAnalyzer(Version.LUCENE_40);
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_40, sa);
Directory dir1 = null;
try {
dir1 = FSDirectory.open(new File("F:\\temp"));
writer = new IndexWriter(dir1, iwc);
Term term = new Term("id", delQ.getId());
writer.deleteDocuments(term);
writer.commit();
writer.close();
} catch (CorruptIndexException e) {
e.printStackTrace();
} catch (LockObtainFailedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (writer != null) {
writer.close();
sa.close();
}
} catch (CorruptIndexException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("索引删除完成");
3,更新索引文件中的一条索引
更新索引文件中的一条索引的理念是:先找到这条索引删除,然后再添加这条更新后的索引
posted @
2013-08-16 12:08 魏文甫 阅读(335) |
评论 (0) |
编辑 收藏
IndexReader reader = DirectoryReader.open(FSDirectory.open(new File("F:\\temp")));// 打开索引
IndexSearcher searcher = new IndexSearcher(reader);
Analyzer analyzer = new SmartChineseAnalyzer(Version.LUCENE_40);
String[] fields = { "questionname","id" };
Occur[] occurs = new Occur[] { Occur.SHOULD,Occur.SHOULD };
Query query = MultiFieldQueryParser.parse(Version.LUCENE_40, "测试 的", fields,
occurs, analyzer);
TopDocs result = searcher.search(query, searcher.getIndexReader()
.maxDoc());
ScoreDoc[] hits = result.scoreDocs;
List<Document> list = new ArrayList<Document>();
for (int i = 0; i <hits.length; i++) {
Document doc = searcher.doc(hits[i].doc);
list.add(doc);
}
System.out.println("搜索list的长度\t→→→→\t"+list.size());
for (Document document : list) {
System.out.println(document.getField("questionname"));
}
analyzer.close();
注:红色字体是输入的检索条件,多个用空格隔开,找到的结果先匹配同时符合多个的结果,结果只是拿过来的document一个list集合,具体结果再解析就行了。
结果如图:
posted @
2013-08-12 17:26 魏文甫 阅读(1167) |
评论 (1) |
编辑 收藏
Connection conn = null;
Statement stat = null;
ResultSet rs = null;
Analyzer sa = new SmartChineseAnalyzer(Version.LUCENE_40);
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_40, sa);
iwc.setOpenMode(OpenMode.CREATE);
Directory dir1 = FSDirectory.open(new File("F:\\temp"));
IndexWriter writer = new IndexWriter(dir1, iwc);
int numIndexed = -1;
FieldType ft = new FieldType();
ft.setIndexed(true);
ft.setStored(true);
ft.setTokenized(true);
FieldType ft2 = new FieldType();
ft2.setIndexed(true);
ft2.setStored(true);
ft2.setTokenized(false);
Class.forName("com.mysql.jdbc.Driver");
conn = (Connection) DriverManager.getConnection(
"jdbc:mysql:///question", "root", "root");
stat = (Statement) conn.createStatement();
rs = stat.executeQuery("select id,questionname from question");
List<String> list = new ArrayList<String>();
while (rs.next()) {
String id = rs.getString("questionname");
String questionname = rs.getString("questionname");
list.add(id);
list.add(questionname);
}
rs.close();
stat.close();
conn.close();
for (String string : list) {
Document doc = new Document();
doc.add(new Field("questionname", string, ft2));
writer.addDocument(doc);
}
numIndexed = writer.maxDoc();
writer.close();
执行完这段程序f盘多一个文件夹temp,里面就是创建好的索引文件了,然后进行根据索引文件查询
posted @
2013-08-12 16:50 魏文甫 阅读(1412) |
评论 (0) |
编辑 收藏
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=GBK" />
<title></title>
<script type="text/javascript" src="jquery-1.8.2.js"></script>
<script type="text/javascript">
$(document).mousemove(function(e) {
var innerHeight = window.innerHeight;
if (e.pageY > innerHeight) {
$("#topDiv").css("display", "block");
}
if (e.pageY < innerHeight) {
$("#topDiv").css("display", "none");
}
});
$("#topIcon").mouseover(function() {
$("#topIcon").css("text-decoration", "none");
$("#topIcon").children("i").removeClass();
$("#topIcon").children("i").addClass("icon-chevron-up");
});
$("#topIcon").mouseout(function() {
$("#topIcon").children("i").removeClass();
$("#topIcon").children("i").addClass("icon-arrow-up");
});
</script>
</head>
<body id="bodyId">
<div id="topDiv"
style="position: fixed;right: 60px;bottom: 60px;display: none">
<a id="topIcon" href="#bodyId" style="background-color: #aaaaaa"><span
style="text-align: justify;display: block;text-decoration: none;width: 14px;background-color: #cccccc">回到顶端</span>
</a>
</div>
<h1>O(∩_∩)O哈哈~</h1>
<h2>(*^__^*) 嘻嘻……</h2>
<h3>O(∩_∩)O~</h3>
<h4>\(^o^)/~</h4>
<h5>$_$</h5>
<h6>o(╯□╰)o</h6>
<h1>O(∩_∩)O哈哈~</h1>
<h2>(*^__^*) 嘻嘻……</h2>
<h3>O(∩_∩)O~</h3>
<h4>\(^o^)/~</h4>
<h5>$_$</h5>
<h6>o(╯□╰)o</h6>
<h1>O(∩_∩)O哈哈~</h1>
<h2>(*^__^*) 嘻嘻……</h2>
<h3>O(∩_∩)O~</h3>
<h4>\(^o^)/~</h4>
<h5>$_$</h5>
<h6>o(╯□╰)o</h6>
<h1>O(∩_∩)O哈哈~</h1>
<h2>(*^__^*) 嘻嘻……</h2>
<h3>O(∩_∩)O~</h3>
<h4>\(^o^)/~</h4>
<h5>$_$</h5>
<h6>o(╯□╰)o</h6>
<h1>O(∩_∩)O哈哈~</h1>
<h2>(*^__^*) 嘻嘻……</h2>
<h3>O(∩_∩)O~</h3>
<h4>\(^o^)/~</h4>
<h5>$_$</h5>
<h6>o(╯□╰)o</h6>
<h1>O(∩_∩)O哈哈~</h1>
<h2>(*^__^*) 嘻嘻……</h2>
<h3>O(∩_∩)O~</h3>
<h4>\(^o^)/~</h4>
<h5>$_$</h5>
<h6>o(╯□╰)o</h6>
<h1>O(∩_∩)O哈哈~</h1>
<h2>(*^__^*) 嘻嘻……</h2>
<h3>O(∩_∩)O~</h3>
<h4>\(^o^)/~</h4>
<h5>$_$</h5>
<h6>o(╯□╰)o</h6>
<h1>O(∩_∩)O哈哈~</h1>
<h2>(*^__^*) 嘻嘻……</h2>
<h3>O(∩_∩)O~</h3>
<h4>\(^o^)/~</h4>
<h5>$_$</h5>
<h6>o(╯□╰)o</h6>
</body>
</html>
posted @
2013-08-07 10:35 魏文甫 阅读(207) |
评论 (0) |
编辑 收藏
求单一登陆和单点登陆的思路及核心代码???
posted @
2013-08-07 09:56 魏文甫 阅读(319) |
评论 (0) |
编辑 收藏
html中中文正则表达式不对的问题 中文的正则表达式:var reg = /^[\u4e00-\u9fa5]$/;(一个中文字符)
放在html中可能出现的问题有:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title></title>
</head>
<body>
<script type="text/javascript">
var reg0 = /^[\u4e00-\u9fa5]$/;
alert(reg0.test("看"));
</script>
</body>
</html>
本页编码为UTF-8时出现的结果可能是错误的,
所以出现此类情况,编码格式改为gb2312(红色标注的编码改为gb2312)
posted @
2013-07-29 15:56 魏文甫 阅读(220) |
评论 (0) |
编辑 收藏
简单的代码:
public static void main(String[] args) {
try {
File allfile = new File("f:\\excel\\total.xlsx");
File file2 = new File("f:\\excel\\xxxxxx.xlsx");
XSSFWorkbook h = new XSSFWorkbook(new FileInputStream(allfile));
XSSFSheet x = h.getSheetAt(0);
XSSFWorkbook hssfWorkbook = new XSSFWorkbook(new FileInputStream(file2));
XSSFSheet hssfSheet = hssfWorkbook.getSheetAt(0);
int ii = hssfSheet.getLastRowNum();//读取的表格行数
System.out.println(ii);
FileOutputStream out_ = new FileOutputStream(allfile);
for (int i = 0; i < ii; i++) {
XSSFRow lastRow = x.createRow(x.getLastRowNum()+1);
XSSFRow xssfRow = hssfSheet.getRow(i);
XSSFCell xssfCell0 = xssfRow.getCell(0);
CellStyle cellStyle0 = xssfCell0.getCellStyle();
CellStyle newStyle0 = h.createCellStyle();
newStyle0.cloneStyleFrom(cellStyle0);
XSSFCell xssfCell0_ = lastRow.createCell(0);
xssfCell0_.setCellStyle(newStyle0);
xssfCell0_.setCellValue(xssfCell0.toString());
XSSFCell xssfCell1 = xssfRow.getCell(1);
CellStyle cellStyle1 = xssfCell1.getCellStyle();
CellStyle newStyle1 = h.createCellStyle();
newStyle1.cloneStyleFrom(cellStyle1);
XSSFCell xssfCell1_ = lastRow.createCell(1);
xssfCell1_.setCellStyle(newStyle1);
xssfCell1_.setCellValue(xssfCell1.toString());
XSSFCell xssfCell2 = xssfRow.getCell(2);
CellStyle cellStyle2 = xssfCell2.getCellStyle();
CellStyle newStyle2 = h.createCellStyle();
newStyle2.cloneStyleFrom(cellStyle2);
XSSFCell xssfCell2_ = lastRow.createCell(2);
xssfCell2_.setCellStyle(newStyle2);
xssfCell2_.setCellValue(xssfCell2.toString());
XSSFCell xssfCell3 = xssfRow.getCell(3);
CellStyle cellStyle3 = xssfCell3.getCellStyle();
CellStyle newStyle3 = h.createCellStyle();
newStyle3.cloneStyleFrom(cellStyle3);
XSSFCell xssfCell3_ = lastRow.createCell(3);
xssfCell3_.setCellStyle(newStyle3);
xssfCell3_.setCellValue(xssfCell3.toString());
XSSFCell xssfCell4 = xssfRow.getCell(4);
CellStyle cellStyle4 = xssfCell4.getCellStyle();
CellStyle newStyle4 = h.createCellStyle();
newStyle4.cloneStyleFrom(cellStyle4);
XSSFCell xssfCell4_ = lastRow.createCell(4);
xssfCell4_.setCellStyle(newStyle4);
xssfCell4_.setCellValue(xssfCell4.toString().toString());
}
h.write(out_);
out_.flush();
out_.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
posted @
2013-07-19 18:02 魏文甫 阅读(627) |
评论 (0) |
编辑 收藏
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=GBK" />
<title></title>
</head>
<body>
<h1>提示离开当前页面的js代码</h1>
<a href="http://www.baidu.com">百度链接</a>
<script type="text/javascript">
if (window != top) {
top.location.href = "login.action";
} else {
if (window.Event) {
window.onbeforeunload = function(event) {
return "你是否要离开此页面,离开此页面信息将不被保存!";
};
} else {
window.onbeforeunload = function() {
return "你是否要离开此页面,离开此页面信息将不被保存!";
};
}
}
</script>
</body>
</html>
posted @
2013-07-18 15:04 魏文甫 阅读(244) |
评论 (0) |
编辑 收藏
Ajax同步加载数据。发送请求时锁住浏览器。需要锁定用户交互操作时使用同步方式。
$.ajax({
url: "some.php",
async: false
})
posted @
2013-07-11 15:48 魏文甫 阅读(451) |
评论 (0) |
编辑 收藏
String data_ = "2013-07-01 15:47:34";SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = simpleDateFormat.parse(data_);
格式yyyy-MM-dd HH:mm:ss是24小时制,yyyy-MM-dd hh:mm:ss是12小时制。
posted @
2013-07-01 15:48 魏文甫 阅读(193) |
评论 (0) |
编辑 收藏
/**
* 得到几天前的时间
*
* @param d
* @param day
* @return
*/
public static Date getDateOfBefore(Date d, int day) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
return now.getTime();
}
/**
* 得到几天后的时间
*
* @param d
* @param day
* @return
*/
public static Date getDateOfAfter(Date d, int day) {
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.DATE, now.get(Calendar.DATE) + day);
return now.getTime();
}
posted @
2013-06-28 17:55 魏文甫 阅读(269) |
评论 (0) |
编辑 收藏
在struts2中配置:<constant name="struts.multipart.saveDir" value="D:\\uploadFiles\\temp\\temp"></constant>
类似的其他的配置有:
<constant name="struts.convention.default.parent.package"
value="crud-default" />
<package name="crud-default" extends="convention-default">
<interceptors>
<interceptor name="checklogin"
class="com.xiaowei.interceptor.CheckLoginInterceptor"></interceptor>
<interceptor-stack name="crudStack">
<interceptor-ref name="store">
<param name="operationMode">AUTOMATIC</param>
</interceptor-ref>
<interceptor-ref name="paramsPrepareParamsStack" />
<interceptor-ref name="checklogin">
<param name="user">user</param>
<param name="exclude">
login,verifyAccount,login.jsp,image
<!--有待添加 -->
</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="crudStack" />
<global-results>
<result name="loginFail" type="dispatcher">/index.jsp
</result>
</global-results>
<!-- <interceptor-stack name="fileUploadMaxSize" class="com.xiaowei.interceptor.CheckFileLengthMax">
<interceptor-ref name="fileUpload"/> <interceptor-ref name="basicStack"/>
</interceptor-stack> -->
</package>
<constant name="struts.multipart.maxSize" value="20480000000"></constant>
<constant name="struts.multipart.saveDir" value="D:\\uploadFiles\\temp\\temp"></constant>
posted @
2013-06-27 13:13 魏文甫 阅读(406) |
评论 (0) |
编辑 收藏
在简单地main函数中输出的结果:0.8999999999999999;而非0.9;因为是以二进制存储的,所以不能除尽1/10。
解决方法有:1,
System.out.printf("%.1f",2.0-1.1); 还有一个网上看到的:
在double变量存入堆时确保精度的方法:
System.out.println(new BigDecimal(1.1)); 输出的值为一大长串为:1.100000000000000088817841970012523233890533447265625
posted @
2012-02-28 19:17 魏文甫 阅读(827) |
评论 (0) |
编辑 收藏
好些天没更新了,有些牵绊耽搁了很久,要慢慢拾起来......我要培养自己做一个有始有终的人。
posted @
2012-02-22 20:46 魏文甫 阅读(150) |
评论 (0) |
编辑 收藏
HTML中的一些对象()
使用DOM-Document Object Model操作对象getElementById();getElementsByName();等
而改变标签里的内容要用.innerHTML,改变链接用.href例如:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function changerButton(){
var link = document.getElementById("links");
link.innerHTML = "NetEasy";//改变a标签里的内容即改变了Sina
link.href = "http://www.163.com";//链接改变了
}
</script>
</head>
<body>
<a href="http://www.sina.com">Sina</a>
<input type="button" value="Change" id="myButton" onclick="changerButton()"/>
</body>
</html>
javascript里的一些应用:例如<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
var count = 0;
var st;
function showDiv() {
count++;
if(count >=10) {
clearTimeout(st);
} else {
var div = document.getElementById("myDiv");
div.innerHTML = div.innerHTML + "I love you!";
st = setTimeout("showDiv()",200);
}
}
</script>
</head>
<body>
<div id="myDiv"></div>
<input type="button" value="I love you!" onclick="showDiv()" />
</body>
</html>
script里可以嵌套if语句等
一些网页里的时间显示也可以用javascript来写例如显示时间的走动的简单的页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div id="timer"></div>
<input type="button" value="showTime" onclick="showTimer()" />
<script type="text/javascript">
function showTimer() {
var mydate =
new Date();
var text = mydate.toLocaleString();
var div = document.getElementById("timer");
div.innerHTML = text;
setTimeout("showTimer()",1000);
}
window.onload = showTimer();
</script>
</body>
</html>
图中时间显示为走动的状态(时间在变)。
posted @
2011-12-05 21:05 魏文甫 阅读(216) |
评论 (0) |
编辑 收藏
JavaScript是编程语言,它跟html,css不同,简单的理解为:html的作用是你所写的网页的内容,css是你对所写网页内容的布局(内容所在的位置,颜色,图片等的美化),JavaScript是对网页等得一些验证,切换的效果等等。JavaScript一般写在最后面(因为网页显示时按顺序显示,一个网页最重要的内容要先显示,再出现效果,而效果要比内容长得多)。
JavaScript可以在里面写if...else语句,for语句,while语句等,但和java的语法不同;例如一个不太规范简单的例子:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title></title>
5 <script type="text/javascript">
6 var a=prompt("请输入a的值:");
7 var b=prompt("请输入b的值:");
8 alert("a+b的和为:"+(parseInt(a)+parseInt(b)));
9 </script>
10 </head>
11 <body>
12 </body>
13 </html>
输入两个值后结果为一个两数和的窗口。
JavaScript写在function中,函数是由事件触发的,例:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title></title>
5 <script type="text/javascript">
6 function sayHello(){
7 var name=document.myform.mytext.value;
8 alert("提交:"+name);
9 }
10 function clearMe(){
11 document.myform.mytext.value="";
12 }
13 </script>
14 </head>
15 <body>
16 <form action="" name="myform">
17 <input type="text" name="mytext" id="" value="" onclick="clearMe()"/>
18 <input type="button" name="click me" value="提交" onclick="sayHello()"/>
19 </form>
20 </body>
21 </html>
输入一个值后弹出一个窗口:例
posted @
2011-12-03 23:17 魏文甫 阅读(326) |
评论 (0) |
编辑 收藏
HTML的定位
HTML中要显示有层次时用定位;定位有绝对定位,相对定位和固定定位。
1.绝对定位:在选择器中用position:absolute;此时它有类似与浮动的效果,相当于脱离了文档流,如:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml"
3 <head>
4 <title></title>
5 <style type="text/css">
6 body{
7 margin:0px;;
8 }
9 .div1{
10 width:100px;
11 height:100px;
12 background-color:#669900;
13 position:absolute;
14 }
15 .div2{
16 width:200px;
17 height:50px;
18 background-color:#aa00ff;
19 }
20 </style>
21 </head>
22 <body>
23 <div
class="div1">div1</div>
24 <div
class="div2">div2</div>
25 </body>
26 </html>
此时div1像浮动了,div2补上div1的位置(即有浮动的效果,div2被div1遮住了)
此时如果定义它的高和距离左右,定义的是该块距离它的上一级(即它的父)的距离
如 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml"
3 <head>
4 <title></title>
5 <style type="text/css">
6 body{
7 margin:0px;;
8 }
9 .div1{
10 width:100px;
11 height:100px;
12 background-color:#669900;
13 position:absolute;
14 top:10px;
15 right:10px;
16 }
17 .div2{
18 width:200px;
19 height:50px;
20 background-color:#aa00ff;
21 }
22 </style>
23 </head>
24 <body>
25 <div
class="div1">div1</div>
26 <div
class="div2">div2</div>
27 </body>
28 </html>
2.相对定位:position:relative;相对定位也有浮动的效果,只是它相对于原来的位置发生了偏移。例如:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml"
3 <head>
4 <title></title>
5 <style type="text/css">
6 body{
7 margin:0px;;
8 }
9 .div1{
10 width:100px;
11 height:100px;
12 background-color:#669900;
13 position:relative;
14 top:10px;
15 left:10px;
16 }
17 .div2{
18 width:200px;
19 height:50px;
20 background-color:#aa00ff;
21 }
22 </style>
23 </head>
24 <body>
25 <div
class="div1">div1</div>
26 <div
class="div2">div2</div>
27 </body>
28 </html>
当在body中为绝对定位时,其父为相对定位如: 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title></title>
5 <style type="text/css">
6 body{
7 margin:0px;
8 }
9 div{
10 width:200px;
11 height:200px;
12 }
13 .div1 {
14 background-color:#ccc;
15 position:absolute;
16 bottom:0px;
17 right:0px;
18 z-index:999;
19 }
20 .div2 {
21 margin-left:60px;
22 width:500px;
23 height:300px;
24 background-color:#ff6600;
25 position:relative;
26 }
27 28 </style>
29 </head>
30 <body>
31 <div
class="div2">DIV2
32 <div
class="div1">DIV1</div>
33 </div>
34 </body>
35 </html>
此时div1的位置是相对于div2的位置来说的。
3.固定定位:固定定位个人认为可以理解为固定于浏览器边框,不随滚动条的滚动而滚动:如:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml"
3 <head>
4 <title></title>
5 <style type="text/css">
6 body{
7 margin:0px;;
8 }
9 .toolbar{
10 height:30px;
11 width:100%;
12 background-color:green;
13 position:fixed;
14 top:0px;
15 left:0px;
16 }
17 .div{
18 width:150px;
19 height:150px;
20 background-color:#ff0000;
21 }
22 </style>
23 </head>
24 <body>
25 <div
class="toolbar"></div><br/>
26 <div
class="div">div1</div><br/>
27 <div
class="div">div2</div><br/>
28 <div
class="div">div3</div><br/>
29 <div
class="div">div4</div><br/>
30 <div
class="div">div5</div><br/>
31 <div
class="div">div6</div><br/>
32 <div
class="div">div7</div><br/>
33 <div
class="div">div8</div> <br/>
34 <div
class="div">div9</div><br/>
35 <div
class="div">div0</div><br/>
36 </body>
37 </html>
posted @
2011-12-01 18:57 魏文甫 阅读(5299) |
评论 (1) |
编辑 收藏