[英]Mercury - How do I set an option element's 'selected' property?
How do I set the selected property of an option
element with Mercury / virtual-dom ? 如何使用Mercury / virtual-dom设置
option
元素的selected属性?
I've tried the following, but no selected
property appears on the <option>
: 我已经尝试了以下操作,但是
<option>
上没有selected
属性:
h('select', {
name: 'selectedRole',
}, [
h('option', {value: 'user', selected: true}, 'User'),
])
Instead, it results in this: 相反,它导致以下结果:
<select name="selectedRole">
<option value="user">User</option>
</select>
After some testing, it appears this is how it works with Mercury. 经过一些测试,看来这就是它与Mercury一起工作的方式。 When you set
selected
to true
on an option
, it does become selected even though the property isn't visible on the HTML element. 当您在某个
option
上将selected
设置为true
时,即使该属性在HTML元素上不可见,它也会被选中。
However, I can only make it work in a small demo, not in my full application. 但是,我只能使其在一个小型演示中运行,而不能在我的完整应用程序中运行。 Thus, there could be a bug in virtual-dom.
因此,虚拟域中可能存在错误。
$("option[value='user']").attr('selected', true);
I have also had this problem with the html5 datalist tag's list attribute. html5 datalist标记的list属性也遇到了这个问题。 One work-around is to use javascript, or jquery, to dynamically assign this attribute.
一种解决方法是使用javascript或jquery动态分配此属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.