你的意思是表单的元素:例如button/input/select&textarea elements?
如果是,则name属性是提交表单时发送的内容.id属性唯一标识页面上的任何元素.
我能想到的最好的例子是单选按钮.
每个单选按钮属于一个集合,该集合具有名称.但是,您可能希望通过id链接到特定按钮.
<input type="radio" name="color" id="c1" value="r"/><label for="c1">Red</label>
<input type="radio" name="color" id="c2" value="y"/><label for="c2">Yellow</label>
<input type="radio" name="color" id="c3" value="b"/><label for="c3">Blue</label>
Run Code Online (Sandbox Code Playgroud)
提交表单时,仅发送选定的选项:(例如黄色)
?color=y
Run Code Online (Sandbox Code Playgroud)