当选择框处于<;状态时,如何显示它;p>;我用javascript做p.text(“test”)吗?
在我使用MVC时,我想显示一个选择框当选择框处于<;状态时,如何显示它;p>;我用javascript做p.text(“test”)吗?,javascript,jquery,drop-down-menu,Javascript,Jquery,Drop Down Menu,在我使用MVC时,我想显示一个选择框 <p id="selectedTrigger"> <select name="devices" id="devices"><!-- Here i get the options with javascript --></select> </p> 它不再显示选择框,只显示文本测试 如何解决此问题?发生的事情是替换和之间的所有内容。如果您使用的是jQuery,则使用.html
<p id="selectedTrigger">
<select name="devices" id="devices"><!-- Here i get the options with javascript --></select>
</p>
它不再显示选择框,只显示文本测试
如何解决此问题?发生的事情是替换
和之间的所有内容。如果您使用的是jQuery,则使用.html()
方法替换其中的内容,或者使用.append()
在
中添加内容
因此,在你的例子中,你必须说:
$('#selectedTrigger').append("TEST");
请注意,这将导致以下代码:
<p ...>
<select ..></select>
TEST
</p>
这将给你:
<p ...>
TEXT
<select ..></select>
</p>
这将为您提供:
<p ...>
<select ..>
TEST
</select>
</p>
试验
这是因为当你调用.text(“TEST”);它取代了的内容,您想做什么?在选择框后显示测试?也许您想在p后面添加文本“测试”?试试$(“#selectedTrigger”)。追加(“测试”)instead@TomHorwood好了:)谢谢@kellax with.html它工作得很好,我可以删除很多行
<p ...>
TEXT
<select ..></select>
</p>
$('#devices').append("TEST");
<p ...>
<select ..>
TEST
</select>
</p>