为什么我不能将jquery对象作为函数中的参数传递?

Ian*_*vis 2 javascript jquery

我正在尝试将一个jQuery选择的对象传递给一个函数,该函数将.html()对其进行处理.

HTML:

<div id="box">this is a box</div>
Run Code Online (Sandbox Code Playgroud)

JS:

var fillBox = function(box, text) {
  box.html(text);
}

(function() {
  var box = $("#box");
  fillBox(box, "new text");
});
Run Code Online (Sandbox Code Playgroud)

"this is a box"即使调用该函数,该框也保持不变并且永远不会更新.我甚至$(box).html(text)在函数内部尝试过,但这并没有解决它.这可以吗?

http://jsbin.com/iqixoj/5/edit

Roc*_*mat 8

你忘记了$.

$(function() {
  var box = $("#box");
  fillBox(box, "new text");
});
Run Code Online (Sandbox Code Playgroud)