I am doing the following :
$(function() {
var $txt = $("#text1");
开发者_StackOverflow callMe($txt, $txt.val());
});
function callMe(t, vlue) {
t.html(vlue)
}
I will be calling the callMe() function multiple times.
Is it Ok to do the way i have shown or is there a better way?
There's no problem with passing jQuery objects around.
It will be much more efficient than re-running the selector each time - that's for sure.
jQuery is JavaScript. And this is absolutely valid in JavaScript. You can even just pass the jQuery object an do this:
function callMe(t) {
t.html(t.val());
}
精彩评论