简体   繁体   English

为什么我无法访问 Javascript 中新添加的元素(模式弹出窗口),即使在开发者控制台中也是如此?

[英]Why can't I access newly added elements (modal popup) in Javascript, even in the developer console?

I'm probably missing something obvious here but I'm pretty experienced with html and javascript and this is throwing me.我可能在这里遗漏了一些明显的东西,但我对 html 和 javascript 非常有经验,这让我很震惊。 I'm writing a browser plugin for Salesforce Lightning users.我正在为 Salesforce Lightning 用户编写浏览器插件。 I want to get access to the form fields in the New Contact screen.我想访问“新建联系人”屏幕中的表单字段。 My script wasn't working and when I drilled down I found the issue and I can reproduce it just in the dev tools:我的脚本不起作用,当我深入研究时,我发现了问题,我可以在开发工具中重现它:

I log into Salesforce, click Contact, then New.我登录到 Salesforce,点击 Contact,然后点击 New。 A New Contact window pops up.弹出一个新联系人 window。

I right click on a form field (eg phone number input) and click Inspect.我右键单击表单字段(例如电话号码输入)并单击检查。 I can see the ID of the element, eg "input-169"我可以看到元素的 ID,例如“input-169”

 <input type="text" id="input-169" maxlength="40" name="MobilePhone" class="slds-input">

I go to the console and type in我 go 到控制台并输入

 document.getElementById('input-169');

The return value is null.返回值为 null。

If I do this for an element that was already there before the New Contact popup window, it works fine.如果我对在 New Contact 弹出窗口 window 之前已经存在的元素执行此操作,则它可以正常工作。

If I try other ways to find the element, for example document.getElementsByTagName(), it does not show up that way either, but other elements that were there before the popup window all work.如果我尝试其他方法来查找元素,例如 document.getElementsByTagName(),它也不会以这种方式显示,但在弹出窗口 window 之前存在的其他元素都可以工作。

If I add my own element next to the one I want (ie at the same DOM level) by editing the html, I can access that new element successfully, but still not access the one that was added by the popup window.如果我通过编辑 html 在我想要的元素旁边添加我自己的元素(即在同一 DOM 级别),我可以成功访问该新元素,但仍然无法访问由弹出窗口 window 添加的元素。

I can reproduce this in Safari, Chrome, and Firefox.我可以在 Safari、Chrome 和 Firefox 中重现这一点。

What's going on and is there any way to tell the browser to notice the elements in the popup window?发生了什么,有什么方法可以告诉浏览器注意弹出窗口 window 中的元素?

The Salesforce.com Lightning interface is using custom elements and the Shadow Dom to build its UI. Salesforce.com Lightning 界面使用自定义元素Shadow Dom来构建其 UI。 To access the invisible elements you need to use the shadowRoot property of the custom elements.要访问不可见元素,您需要使用自定义元素的shadowRoot 属性

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么即使我在模式弹出窗口中添加了 Onclick 事件,我的 Asp 按钮也不起作用? - Why my Asp button doesn't works even i added Onclick Event inside modal popup? 为什么我不能在.load()回调函数中访问新加载的DOM元素? - Why can't i access newly loaded DOM elements in the .load() callback function? 为什么我无法使用Javascript访问html元素 - Why can't I access my html-elements in Javascript 为什么我不能在 Javascript 中访问这个 object 的元素? - Why can't I access the elements of this object in Javascript? 如何通过 Chrome 浏览器开发者控制台中的 Javascript 代码关闭模态弹出窗口? - How to close a Modal Popup via Javascript code within Chrome Browser Developer Console? Javascript:在DOM中找不到新添加的表单输入 - Javascript: Can't find newly added form inputs in the DOM 在Javascript Dom中,无法选择新添加的元素? - in Javascript Dom ,the newly added element can't be selected? 为什么我无法访问 Javascript 中的样式元素? Firefox 控制台错误消息说它是“空” - Why can't I access the style element in Javascript? Firefox console error message says it's “Null” 如何在Chrome开发者工具JavaScript控制台中将CoffeeScript访问JS编译的vars? - How can I access CoffeeScript to JS compiled vars in the Chrome Developer Tools JavaScript Console? 如何从Google Developer Console中的Dialog页面访问Javascript? - How can I access Javascript from Dialog page in Google Developer Console?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM