备忘只用,半成品,代码不完全,没引用相关js包则无法运行.
<!DOCTYPE html>
<html>
<head>
<title>Follow me!</title>
<link rel="stylesheet" type="text/css" href="../styles/core.css"/>
<script type="text/javascript" src="../scripts/jquery-1.4.js"></script>
<script type="text/javascript" src="../scripts/jqia2.support.js"></script>
<script type="text/javascript">
$(function() {
$("<p>Hi there!</p>").insertAfter("#followMe");
$("#str").attr("size","130");
$("#regex").attr("size","130");
$("#btn").text("go").click(function (){
var str = $("#str").val();
var regex = $("#regex").val();
say(str);
executeRegex(str,regex);
})
///^\d{2,4}$/
});
function executeRegex(str,regex){
//var regex = /^\d{2,4}$/
var reg = new RegExp(regex);
if(reg.test(str)){
say(str + " OK");
}else{
say(str + " BAD");
}
}
</script>
</head>
<body>
<p id="followMe">Follow me!</p>
<div>
<label>Test string: </label>
<input id="str"/>
</div>
<div>
<label>Regular expression: </label>
<input id="regex" />
</div>
<div>
<button id="btn"></button>
</div>
</body>
</html>