<html>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<head></head>
<script type="text/javascript" src="jquery.js"></script>
<script>
function text_validate(maxlength,minlength){
this.text;
this.length;
this.maxlength = maxlength;
this.minlength = minlength;
}
text_validate.prototype.check = function(){
var length = document.getElementsByTagName('textarea')[0].value.length;
var frm = document.forms[0];
if(length < this.minlength){
alert('can not submit,less then');
return false;
}else if(length > this.maxlength){
alert('more over');
return false;
}
// frm.submit();
}
$(document).ready(function(){
$('button').bind('click',handler);//bind方法
})
function handler(){
var validate = new text_validate(100,10);
validate.check();
var sl_v = new select_validate();
sl_v.check();
sl_v.selectedValue();
}
function select_validate(){
this.length;
this.selectedValue;
}
select_validate.prototype.check = function(){
var sl = document.getElementById('sl');
var options = sl.options;
var length = options.length;
for(var i=0; i<length;i++){
if(options[i].value == 'hello'){
return false;
}}
var item = document.createElement('option');//功能类似于
item.text = "你好";//$("#sl").append("<option value="hello">你好</option>")
item.value = "hello";
sl.add(item)
options[length].selected = true;
}
select_validate.proptotype.selectedValue = function(){
var sl = document.getElementById('sl');
var options = sl.options;
}
</script>
<body>
<form action="">
<textarea></textarea>
<button>bt</button>
<select id="sl">
<option value="11">1</option>
<option value="22">2</option>
<option value="33">3</option>
</select>
</form>
</body>
</html>