日期:2014-05-16  浏览次数:20278 次

新人求助, jquery的一个小问题
 $.fn.show=function(){
alert($(this).val());
};  

$("#show").click(function(){$.fn.show();});


<input type="button" value="showval" id="show">

这几行代码, 我是想点击button之后弹出showval这个字符串的。

但是现在的结果是undefined
求助

------解决方案--------------------
$.fn.show=function(node){
alert($(node).val());
};  

$("#show").click(function({$.fn.show($("this"));});
------解决方案--------------------
<input type="button" value="showval" id="show">
<script type="text/javascript">
$("#show").click(function(){
alert($(this).val());
});
</script>
------解决方案--------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<title>无标题文档</title>
<script type="text/javascript">
(function($){
$.fn.showBox=function(){
//alert(this.attr('value'));
return this.attr('value','#f00');
}
})(jQuery);

jQuery(function($){
$("#show").click(function(){
$(this).showBox();
});
});
</script>
</head>

<body>
<input type="button" value="showval" id="show" />
</body>
</html>