如何将div放在文本框中 [英] How to put a div inside a textbox

查看:120
本文介绍了如何将div放在文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对SO提出问题的部分是键入标签。当您键入标记并单击它时,div会进入文本框。 (至少这是我认为发生)。我怎么能把一个div里面的文本框呢?目前我只能使用以下内容将文本框的值更改为下拉项:

Part of asking a question on SO is typing tags. When you type a tag and click it, a div goes into the textbox. (at least that's what i think is happening). How can i put a div inside a textbox like that? Currently I can only change the value of the textbox to the dropdown item using this:

JQUERY:

$('.item_display').click(function(){
$('#Result').css("display" , "none");
var item = $(this).text();

$('#userInput').val(item);
});

HTML:

<input type='text' id='userInput' autocomplete='off' /> 
<div id='Results'></div>  //this is the dropdown menu where .item_display appears


推荐答案

插件Chosen是一个很好的例子,如何做到这一点。这个想法是什么似乎是一个文本框真的不是。容器DIV跨越所需元素的宽度。文本框位于左侧,并跨越您所在区域的宽度。当您键入和添加元素时,新的div出现在文本框的左侧,将文本框向右推,并重新缩放宽度。在各种插件中可能有这种实现,但我已经与Chosen合作,

The plugin Chosen is a good example of how to do this. The idea is what appears to be a text box really isn't. A container DIV spans the width of your desired element. A textbox sits to the left and spans the width of your area. As you type and add elements, new divs appear to the left of the textbox pushing the textbox right and re-scaling the width. There probably are may implementations of this in various plugins but I've worked with Chosen,

http://harvesthq.github.com/chosen/

这篇关于如何将div放在文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆