在多个单一复选框上添加验证

时间:2016-09-05 09:29:28

标签: javascript jquery checkbox eloqua

我有一组关于活动主题的单一复选框。我想要复选框是必需的。该代码将在Eloqua中使用,因此HTML代码无法更改,以及onsubmit函数。

<div id="formElement1"><input name="singleCheckbox" type="checkbox"><label style="margin-left: 4px">Topic 1</label></div>
<div id="formElement2"><input name="singleCheckbox2" type="checkbox"><label style="margin-left: 4px">Topic 2</label></div>
<div id="formElement3"><input name="singleCheckbox3" type="checkbox"><label style="margin-left: 4px">Topic 3</label></div>
<div id="formElement4"><input name="singleCheckbox4" type="checkbox"><label style="margin-left: 4px">Topic 4</label></div>
<div id="formElement5"><input name="singleCheckbox5" type="checkbox"><label style="margin-left: 4px">Topic 5</label></div>

1 个答案:

答案 0 :(得分:0)

假设您有权访问jQuery,这是添加&#39; required&#39;的简单代码。属性为formElement1&#39;元素:

$('#formElement1').attr('required', true);

否则,使用裸javascript:

document.getElementsById("formElement1").setAttribute("required", true);