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

请问为什么会出错?
请问alert( $("#trimTest").rtrim(" test ")); 为什么会出错?
1、alert(jQuery.rtrim(" test "));中的jQuery是不是一个对象
2、$("#trimTest")也是返回一个jQuery对象,alert( $("#trimTest").rtrim(" test ")); 应该不会出错啊!

   


<!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>
<title>插件2,ltrim,rtrim</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- 引入jQuery -->

<script src="Js/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
  //插件编写
  ; (function ($) {
  $.extend({
  ltrim: function (text) {
  return (text || "").replace(/^\s+/g, "")
  },
  rtrim: function rtrim(text) {
  return (text || "").replace(/\s+$/g, "")
  }
  });
  })(jQuery);

  //插件应用
  $(function () {
  alert(jQuery.rtrim(" test "));
  alert( $("#trimTest").rtrim(" test "));  
  });

</script>
</head>
<body>
<textarea id="trimTest" rows="5" cols="20"></textarea>

</body>
</html>


------解决方案--------------------
Object doesn't support property or method 'rtrim'
------解决方案--------------------
typeof jQuery //function 函数
typeof $("#trimTest") //object 对象