<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>
JS 原型应用
猜你喜欢
转载自zhaoaiqing.iteye.com/blog/2348895
今日推荐
周排行