这是我的js代码:
function myfunction(){
$("#label_startDate[0]")[0].outerHTML;
}这是html部分:
<label id="label_startDate[0]" class="" style="">
<span id="star_startDate[0]" style="display: none; color: red">*</span>
<input name="startDate[0]" id="startDate[0]" value="2015-06-02" readonly="" class="forDatePicker hasDatepicker" size="14" onchange="changeEndDate(0); calculateDaysDuration('@[0]', 0); "type="text">
</label>由于我从标签中有一个奇怪的id格式,所以我无法获得outerHTML。我该怎么办?我不能更改id label_starDate.
发布于 2015-06-02 11:33:25
使用\\转义[],也可以使用.prop()访问属性
$("#label_startDate\\[0\\]").prop("outerHTML");来自文档
要使用任何元字符(如#$%&‘()*+,./:;<=>?@[]^’{x}})作为名称的字面部分,必须用两个反斜杠:\来转义。
$(function() {
alert( $("#label_startDate\\[0\\]").prop("outerHTML"))
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label id="label_startDate[0]" class="" style="">
<span id="star_startDate[0]" style="display: none; color: red">*</span>
<input name="startDate[0]" id="startDate[0]" value="2015-06-02" readonly="" class="forDatePicker hasDatepicker" size="14" onchange="changeEndDate(0); calculateDaysDuration('@[0]', 0); "type="text">
</label>
https://stackoverflow.com/questions/30594922
复制相似问题