防止 struts 2 自动生成 id
Prevent struts 2 from autogenerating id
以下元素是在 struts 2.
中使用 id 属性创建的
<s:select style="min-width:7.5em;max-width:15.5em;" class="form-control" headerKey="SELECT" headerValue="SELECT" list="costCenters" required="true" name="costCenter" />
我不想要这个 ID,因为稍后我会 'jquery.clone()' 它。
当前输出:
<select name="costCenter" id="formName_costCenter" class="form-control" style="min-width:7.5em;max-width:15.5em;" required="true">
<option value="SELECT" selected="selected">SELECT</option>
<option value="COST CENTER 1">COST CENTER 1</option>
<option value="COST CENTER 2">COST CENTER 2</option>
</select>
期望:
<select name="costCenter" class="form-control" style="min-width:7.5em;max-width:15.5em;" required="true">
<option value="SELECT" selected="selected">SELECT</option>
<option value="COST CENTER 1">COST CENTER 1</option>
<option value="COST CENTER 2">COST CENTER 2</option>
</select>
struts.xml 有
<constant name="struts.ui.theme" value="simple"/>
Struts id
属性是自动生成的,但您可以手动设置 id
属性。 <s:select>
标签的 id 属性表示 HTML id
属性。
您无法阻止 Struts 生成 id
属性,除非您更改从 <s:select>
标记呈现 HTML 的模板。您可以阅读有关 Themes and Templates in the Tag Developer's Guide. You can also read this 答案的更多信息,以帮助理解 Struts UI 标签。
另一种使用 jQuery 从元素中删除属性的方法是 removeAttr()
函数。
$("#formName_costCenter").removeAttr("id");
以下元素是在 struts 2.
中使用 id 属性创建的<s:select style="min-width:7.5em;max-width:15.5em;" class="form-control" headerKey="SELECT" headerValue="SELECT" list="costCenters" required="true" name="costCenter" />
我不想要这个 ID,因为稍后我会 'jquery.clone()' 它。
当前输出:
<select name="costCenter" id="formName_costCenter" class="form-control" style="min-width:7.5em;max-width:15.5em;" required="true">
<option value="SELECT" selected="selected">SELECT</option>
<option value="COST CENTER 1">COST CENTER 1</option>
<option value="COST CENTER 2">COST CENTER 2</option>
</select>
期望:
<select name="costCenter" class="form-control" style="min-width:7.5em;max-width:15.5em;" required="true">
<option value="SELECT" selected="selected">SELECT</option>
<option value="COST CENTER 1">COST CENTER 1</option>
<option value="COST CENTER 2">COST CENTER 2</option>
</select>
struts.xml 有
<constant name="struts.ui.theme" value="simple"/>
Struts id
属性是自动生成的,但您可以手动设置 id
属性。 <s:select>
标签的 id 属性表示 HTML id
属性。
您无法阻止 Struts 生成 id
属性,除非您更改从 <s:select>
标记呈现 HTML 的模板。您可以阅读有关 Themes and Templates in the Tag Developer's Guide. You can also read this 答案的更多信息,以帮助理解 Struts UI 标签。
另一种使用 jQuery 从元素中删除属性的方法是 removeAttr()
函数。
$("#formName_costCenter").removeAttr("id");