简体   繁体   English

动态添加 <div> 内 <input>

[英]Dynamically add <div> inside <input>

I want to add <div> inside <input> 我想在<input>内添加<div> <input>

<input type="submit"  
  name="body_0$main_0$contentmain_0$maincontent_1$contantwrapper_0$disclamerwapper_1$DisclaimerAcceptButton"
  value="I understand and agree to all of the above "  
  onclick="return apt();"  
  id="DisclaimerAcceptButton"
  class="DisclaimerAcceptButton">

The button is too long so I want to split its caption into two lines. 该按钮太长,因此我想将其标题分为两行。 I don't have access to pure html since everything is dynamic. 由于所有内容都是动态的,因此我无法访问纯HTML。

input elements cannot have descendants : input元素不能具有后代

 <!ELEMENT INPUT - O EMPTY -- form control --> ^^^^^ 

However, if you can change the code that generates the button, you can use button instead: 但是,如果可以更改生成按钮的代码,则可以改用button

<button name="body_0$main_0$contentmain_0$maincontent_1$contantwrapper_0$disclamerwapper_1$DisclaimerAcceptButton" onclick="return apt();" id="DisclaimerAcceptButton" class="DisclaimerAcceptButton"> 
    I understand and agree to <br />
    all of the above
</button>

This lets you style the content of the button however you want to. 这使您可以随意设置按钮内容的样式。

A div is a block level HTML element and it shouldn't be added inside the button in such a way. div是块级HTML元素,不应以这种方式将其添加到按钮内部。 You can however use CSS to specify a width to the button, and thus acquire the multi-lineness that you're looking for. 但是,您可以使用CSS来指定按钮的width ,从而获得所需的多线度。

您不能在输入元素内添加div(除非您希望在输入的值中添加div)。

No can't do. 不行 And if it works on some browser, it's not guaranteed to work anywhere else, because it doesn't follow the standards. 而且,如果它可以在某些浏览器上运行,则不能保证它可以在其他任何地方运行,因为它不符合标准。

Only you need: 仅您需要:

<input type="checkbox" id="a"/>
<label for="a"><div>... div content ...</div></label>

Like somebody write in input you cannot put any element but in label for it can. 就像有人在输入中编写内容一样,您不能在标签中放置任何元素,但可以在其中添加标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM