js与jquery 学习随笔(一)

来源:互联网 发布:tensorflow下载教程 编辑:程序博客网 时间:2024/06/10 22:34

 

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

原创粉丝点击