刚学java,老板让做JSP,实在找不到头绪……
要求:首先一个要建一个input,在框内输入一个数字n,如果数字n>=0,则光标移开输入框就生成一个n行4列的表,每一格都能填写数据,如果n<0,那么光标移开没有反应,哪位帮忙写下code啊?让小弟学习下~
要求:首先一个要建一个input,在框内输入一个数字n,如果数字n>=0,则光标移开输入框就生成一个n行4列的表,每一格都能填写数据,如果n<0,那么光标移开没有反应,哪位帮忙写下code啊?让小弟学习下~
1,写个jsp页面;
2,直接在页面js里面控制,可使用ajax;
2.1,首先判断输入框的值;
2.2,如果符合条件,则动态的增加表格,否则return;
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 type="text/javascript">
function createTable(op) {
alert(op.value);
var tempCode = 0;
if(op.value.length > 0) {
tempCode = parseInt(op.value,10);
if(tempCode > 0) {
var tempHtml = "<table>";
for(var i=1;i<=tempCode;i++) {
tempHtml = tempHtml + "<tr id='tr"+i+"'>";
for(var col=1;col<=4;col++) {
tempHtml = tempHtml + "<td style='border: 1px solid #000000;'><input type='text' style='border-width:0px; width: 50px;'></td>";
}
tempHtml = tempHtml + "</tr>";
}
tempHtml = tempHtml + "</table>";
//alert("tempHtml:"+tempHtml);
document.getElementById("divContent").innerHTML = tempHtml;
//alert(document.getElementById("divContent").innerHTML);
}
}
}
</script>
</head>
<body>
<form action="">
<input type="text" id="txtCode" onblur="createTable(this)" style="width: 100px">
<div id="divContent" ></div>
</form>
</body>
</html>