【问题标题】:Is it possible to have more than one id attributes within a single html button?一个 html 按钮中是否可以有多个 id 属性?
【发布时间】:2015-07-06 02:55:52
【问题描述】:

例如,我在表单中有一个按钮

<button id="test1 test2" value="test">TEST</button>

出于某种原因,我希望 id "test1" 用于使用 php 从按钮获取 $_POST 值,而 id "test2" 用于使用 javascript 捕获用户的 onclick 事件。

这是可能的还是只是一些令人不安的问题?

提前致谢。

【问题讨论】:

标签: javascript php html


【解决方案1】:

每个 html 页面可以有多个类和一个 Id,

id 旨在识别(区分)元素与将多个元素与同一个类组合在一起的类

并且名称在表单中不必是唯一的。 重复它们最常见的用途是收音机:

<form>
    <input type="radio" name="my_radio" value="1">
    <input type="radio" name="my_radio" value="2">
    <input type="radio" name="my_radio" value="3">
</form>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-31
    • 1970-01-01
    • 2018-05-21
    • 1970-01-01
    • 1970-01-01
    • 2011-10-05
    • 2022-06-20
    相关资源
    最近更新 更多