Tho*_*ock 4 javascript jquery jquery-selectors dynamics-crm-2011
我正在尝试使用以下ID访问MS CRM 2011中的元素:account | NoRelationship | Form | B_GenerateInvoice-Large
我可以在IE开发人员工具中看到这个元素:

不幸的是,我总是在尝试找到这个元素时得到null.
我尝试过以下方法:
alert(document.getElementById('account|NoRelationship|Form|B_GenerateInvoice-Large'));
alert($("[id='account|NoRelationship|Form|B_GenerateInvoice-Large]").html());
alert($(jq("account|NoRelationship|Form|B_GenerateInvoice-Large")).html()); // jq() adds the '#' and escapes special characters
alert($("#account|NoRelationship|Form|B_GenerateInvoice-Large").html());
alert(document.getElementById("#account\\|NoRelationship\\|Form\\|B_GenerateInvoice-Large"));
alert($("#account\\|NoRelationship\\|Form\\|B_GenerateInvoice-Large").html());
Run Code Online (Sandbox Code Playgroud)
这些都找不到元素.
我错过了一些明显的东西吗?
解:
javascript在iframe中,而元素在iframe之外.
我没有设法解决它.
如果你想使用任何元字符(例如!"#$%&'()*+,./:; <=>?@ [] ^`{|}〜)作为字面的一部分name,你必须用两个反斜杠转义字符:\\.例如,如果你有一个id ="foo.bar"的元素,你可以使用选择器$("#foo \\.bar").W3C CSS规范包含有关有效CSS选择器的 完整规则集.
试试这个:
$('#account\\|NoRelationship\\|Form\\|B_GenerateInvoice-Large')...
Run Code Online (Sandbox Code Playgroud)
编辑:我已成功测试我的小提琴在Chrome,Firefox 4,IE9,IE8和IE7,它工作正常.