`

JS 原型应用

 
阅读更多
<html>
<body>

<input type="text" name="txtName" value="123" id="txtName">

<input type="button" name="btn" id="btn" value="confirm"></input>

<script>

  (function(window){
 
var jQuery = function(id) {
return jQuery.fn.init(id);
}
jQuery.fn = jQuery.prototype;

jQuery.fn = {
init:function(id){
this.id = id;
this.element =  document.getElementById(this.id);
return this;
},
html: function(html) {
   this.element.innerHTML = html;
           return this;
       }
  
};
jQuery.fn.init.prototype = jQuery.fn;

jQuery.fn.val = function(){
return this.element.value;
   }

window.$ = window.jQuery = jQuery;

  })(window);

 
  (function($){
 
$.fn.click = function(callback){
this.element.onclick = callback;
return this;
}
$.trim = function(str){
return str.replace(/(^\s*)|(\s*$)/g, "");
}
  })(jQuery)
 
  $("btn").click(function(){
alert($("txtName").val())
  })
alert("11" + $.trim("  fdsafdsa "));
</script>

</body>

</html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics