创建输入作为输入的子代 [英] Create input as child of input

查看:92
本文介绍了创建输入作为输入的子代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以创建一个文本的小孩的按钮?

Is it possible to create a button that is the child of an text?

<input type="text">
    <input type="button" />
</input>

我想要的是我想组合一个组合框。请参阅这个小提琴。在jquery中执行此操作,该按钮不会显示。在普通的html中,第二个输入不是第一个的孩子(至少在Chrome中)。

The reason I ask is I would like to make a combo box. See this fiddle. Doing this in jquery, the button does not appear. Doing it in regular html, the 2nd input is not a child of the first (in Chrome at least).

我可以在文档中放置一个文本和按钮,但是我喜欢在示例中创建文本框,所以后来的值可以被检索为:$(#test).val();

I could put a text and button in a span, but I prefer to create the text box like in the example so later the value can be retrieved like: $("#test).val();

PS我知道其他组合框插件存在,我想自己滚动学习目的。

PS I know other combo box plugins exist. I would like to roll my own for learning purposes.

推荐答案

这将导致无效的HTML,所以它不可能这样做
你可以做的是创建一个div,它是一个块元素,并用一个文本框+按钮内联元素填充。

This will result in invalid HTML, so its not possible to do this. What you can do is create a div, which is a block element and fill it with a text box + button Inline elements.

在你的CSS中有一些样式,你可以使你的div看起来像一个文本框,你的文本框就像一个div,没有边框和斜面,导致了一些看起来像你想要实现的东西。

With some styling in your CSS you can make your div look like a textbox and your textbox like a div, without borders and bevels. Resulting in something that looks like the thing you are trying to achieve here.

要摆脱您输入的文本框外观,请使用 #YourTextBox {border:none;}

To get rid of the textbox look on your input use #YourTextBox {border: none;}

这篇关于创建输入作为输入的子代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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