如何在REF中使用输入类型日期?
我可以隐藏输入类型文件
并从其他元素触发它:
<button @click="$refs.fileRef.click()"></button>
<input type="file" ref="fileRef" style="display: none">
但是当我使用输入类型date日期
尝试时,它无效:
<button @click="$refs.dateRef.click()"></button>
<input type="date" ref="dateRef" style="display: none">
我可以激活该方法日期选择器
通过ref
?
I can hide input type file
and trigger it from another element like so:
<button @click="$refs.fileRef.click()"></button>
<input type="file" ref="fileRef" style="display: none">
but when I try that with input type date
it doesn't work:
<button @click="$refs.dateRef.click()"></button>
<input type="date" ref="dateRef" style="display: none">
Any way I can activate the date picker
via ref
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以只做
$ refs.dateref.showpicker()
:You could just do
$refs.dateRef.showPicker()
:一个解决方案似乎强制显示picker在单击上使用
onclick =“ this.showpicker()”
,但是如doc https://developer.mozilla.org/en-us/docs/web/api/htmlinputelement/showpicker
如果您尝试在框架中打电话,您将有一个安全例外
a solution seems to force display the picker on click with
onclick="this.showPicker()"
but as say in the doc https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/showPicker
if you try call in a frame you will have a security exception
您可以尝试
showpicker()
方法在单击按钮时激活日期选择器。在上面的代码段中,我遇到了跨域安全错误,这也提到在这里 。您能在项目中尝试一下吗?
Can you try
showPicker()
method to activate the date picker on button click.In above code snippet, I am getting cross-domain security error which is also mentioned here. Can you please give a try in your project.