【问题标题】:Changing input into Button将输入更改为 Button
【发布时间】:2016-02-06 22:08:54
【问题描述】:

我正在测试Material Design Light component library。

我有一些按钮形式的输入属性,我想知道如何将这些输入按钮切换到按钮属性,因为 MDL 使用按钮属性。虽然我不知道如何做到这一点并保留输入属性所具有的属性,例如“accept”、“type”等。我目前正在测试的代码就在这里:

https://jsfiddle.net/ErraticFox/46654fzy/

<input id="uploadSound" accept='audio/wav, audio/x-wav, audio/mpeg, audio/vorbis, application/ogg' type="file">

<!-- 

MDL Button:

<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent">
  Button
</button> 

-->

【问题讨论】:

    标签: html button input


    【解决方案1】:

    在这种情况下,您无法更改按钮的输入,因为它会失去功能,但您可以通过隐藏 &lt;input&gt; 并利用 &lt;label&gt; 和 for 属性将事件委托给输入给定的id。

    示例:https://jsfiddle.net/k2eau0oe/

    【讨论】:

    • 完美运行!我不知道“for”属性。
    猜你喜欢
    • 2021-04-26
    • 2011-08-11
    • 2010-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-12
    • 2013-03-08
    • 2020-09-11
    相关资源
    最近更新 更多