- 下拉框添加属性并获取
//html 设置属性
<select name="contractId" id="contractId" class="form-control m-b" required>
<option th:supplier_id = "${contract.supplierId}"></option>
</select>
======js=======
//获取
$("#contractId").change(function () {
var id = $(this).find("option:selected").attr("supplier_id");
})
2、利用模板创建style等元素
<script id="gongzuozulinBody" type="text/html">
*{
margin: 0;
padding: 0;
font-size: 1rem;
}
</script>
<script>
//设置元素
var box = document.getElementById("gongzuozulinBody").innerHTML;
var style = document.createElement("style");
style.innerHTML= box;
style.id='element';
document.getElementsByTagName("head").item(0).appendChild(style);
//删除元素
var gongzuozulinBody= document.getElementById('gongzuozulinBody');
if(gongzuozulinBody!= null){
gongzuozulinBody.remove();
}
</script>