js与jquery 学习随笔(一)

 

<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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值