我正在尝试将一个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)在函数内部尝试过,但这并没有解决它.这可以吗?
你忘记了$.
$(function() {
var box = $("#box");
fillBox(box, "new text");
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
509 次 |
| 最近记录: |