3. Jquery表单验证(只能输入数字,检查复选框)
<html>
<head>
<title></title>
<style type="text/css">
#error
{
padding-left:15px;
color:Red;
}
</style>
<script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#error").hide();
$("#Button1").click(function () {
var $val = $("#Text1").val();
var code;
for (var i = 0; i < $val.length; i++) {
//charAt()获取指定位置字符串,charCodeAt()返回该字符串的编码
//0的ASCII是48,9的ASCII是57
var code = $val.charAt(i).charCodeAt(0);
if (code < 48 || code > 57) {
$("#error").show();
break;
}
else {
$("#error").hide();
}
}
});
});
</script>
</head>
<body>
<div>
Name:<input id="Text1" type="text" /><span id="error">Please enter numeric</span>
</div>
<input id="Button1" type="button" value="button" />
</body>
</html>
2.检查复选框是否被选中
<!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>
<style type="text/css">
#error
{
padding-left:15px;
color:Red;
}
</style>
<script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#error").hide();
$("#Button1").click(function () {
var $val = '';
var count = $('input:checkbox:checked').length;
if (count == 0) {
$("#error").show();
}
else {
$("#error").hide();
$("input:checkbox").each(function () {
if ($(this).is(':checked')) {
$val += $(this).val();
}
})
alert($val);
}
});
});
</script>
</head>
<body>
<div>
<input id="Checkbox1" type="checkbox" value='Hotdogs $2' />Hotdogs $2<br />
<input id="Checkbox2" type="checkbox" value='Chocolate $5' />Chocolate $5<br />
<input id="Checkbox3" type="checkbox" value='Cake $3' />Cake $3<br />
<input id="Checkbox4" type="checkbox" value='Ice $4' />Ice Crime $4<br />
<span id="error">Please select checkbox as least</span>
</div>
<input id="Button1" type="button" value="button" />
</body>
</html>
4 改错:
public class Something {
public int addOne(final int x) {
return ++x;
}
}
这个比较明显。
答案: 错。int x被修饰成final,意味着x不能在addOne method中被修改。
5 Jsp内置对象及其方法。
6.冒泡法
7.用一条sql语句查询出“每门”课程都大于80分的学生姓名
Name chengji fengshu 张三 数学 75 张三 语文 81 李四 数学 90 李四 语文 76 王五 数学 81 王五 语文 100 王五 英语 90
思路:先查出低于80分的学生名单,然后再用姓名作为条件对比,排除刚才查到的学生 SQL Server: select distinct [Name] from [表] where [Name] not in ( select [Name] from [表] where [fengshu]<=80 )
2. 在web应用开发过程中经常遇到输出某种编码的字符,如ISO8859-1等 如何输出一个某一种编码的字符串?
public String translate (String str) {
String tempStr = "";
try {
tempStr = new String(str.getBytes("ISO-8859-1"), "GBK");
tempStr = tempStr.trim();
}
catch (Exception e) {
System.err.println(e.getMessage());
}
return tempStr;
}
public String translate (String str) {
String tempStr = "";
try {
tempStr = new String(str.getBytes("ISO-8859-1"), "GBK");
tempStr = tempStr.trim();
}
catch (Exception e) {
System.err.println(e.getMessage());
}
return tempStr;
}