文本框自动变长
<input type="text" value="" class=\"queryInput\" />
var curNode = "input.queryInput"; var curWidth = $(curNode).eq(0).width(); var curMaxWidth = 700; $(curNode).eq(0).keyup(function() { var curTxtWidth = $(curNode).eq(0).width(); var node = $("#widthAuto"); if (node.length > 0) { node = $("#widthAuto"); node.html($(this).val()) } else { node = $("<span id=\"widthAuto\" style=\"visibility:hidden;\">" + $(this).val() + "</span>"); $("body").append(node) } var curAllWidth = node.width() + 149; if (curWidth > curAllWidth) { $(curNode).eq(0).css("width", curWidth) } else { if (curMaxWidth > curAllWidth) { $(curNode).eq(0).css("width", curAllWidth) } } })
记得引用Jquery!