我有这个 HTML,其中 ID 包含特殊字符:
<input type="text" id="e09b989c-7201-4b7e-8fd4-a2309db6d356|b5d9746a-7f7c-432d-a4ef-a5e0011d989d|IssueDate" name="e09b989c-7201-4b7e-8fd4-a2309db6d356|b5d9746a-7f7c-432d-a4ef-a5e0011d989d|IssueDate" value="">
<input type="hidden" id="Type_e09b989c-7201-4b7e-8fd4-a2309db6d356|b5d9746a-7f7c-432d-a4ef-a5e0011d989d|IssueDate" name="Type_e09b989c-7201-4b7e-8fd4-a2309db6d356|b5d9746a-7f7c-432d-a4ef-a5e0011d989d|IssueDate" value="date">
<br>
<input type="text" id="1c36b33a-85d8-4811-93f6-a5e000ad985c|b795c0b4-1c8b-4d9e-95c5-a5e0011d8505|FromDate(mm/dd/yyyy)" name="1c36b33a-85d8-4811-93f6-a5e000ad985c|b795c0b4-1c8b-4d9e-95c5-a5e0011d8505|FromDate(mm/dd/yyyy)" value="" class="">
<input type="hidden" id="Type_1c36b33a-85d8-4811-93f6-a5e000ad985c|b795c0b4-1c8b-4d9e-95c5-a5e0011d8505|FromDate(mm/dd/yyyy)" name="Type_1c36b33a-85d8-4811-93f6-a5e000ad985c|b795c0b4-1c8b-4d9e-95c5-a5e0011d8505|FromDate(mm/dd/yyyy)" value="DateTime">
我正在使用这个 JQuery 来更新它们:
$("input[id^='Type_']").each(function () {
if ($(this).val() == "date" || $(this).val() == "DateTime") {
console.log($(this).attr('id'));
var id = $(this).attr('id').replace("Type_", "").replace(/\|/g, "\\|").replace(/\//g, "\\\\\/").replace(/\)/g, "\\\\\)").replace(/\(/g, "\\\\\(");
console.log(id);
console.log(">>" + $("#" + id));
$("#" + id).val(id);
}
});
但是第二个Id包含“|”并且“(”未被选中。 我在这里测试:http://jsfiddle.net/MWadX/446/
有人可以帮助我吗? 谢谢。
最佳答案
关于javascript - JQuery 选择 Id 中含有特殊字符的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36471731/