getElementById是浏览器中JavaScript常用的一种基本方法,用于通过ID检索HTML或XML文档中的特定元素节点。
我可以使用带有多个 id 的 document.getElementById() 吗?
doStuff(document.getElementById("myCircle1" "myCircle2" "myCircle3" "myCircle4")); 这不起作用,所以我需要逗号或分号才能使其起作用吗?
我可以在“getElementById”中获取触发该功能的按钮ID值吗? 我正在尝试编写一个通用函数,其中 getElementById 应该与按钮 ID 相同,因此触发...
我有一个 tumblr,我在其中根据图像出现的帖子大小加载不同的 url,使用 javascript 和 tumblr 的主题运算符 {photoUrl-250}、{photoUrl-400} 等。用户 b ...
有什么理由使用 document.getElementById 而不是 ID 本身吗?
例如,要从 DOM 中删除元素,myEl.remove() 的效果与 document.getElementById("myEl").remove() 一样(在 Firefox 和 Chrome 中)
在 Python 中使用 Selenium 基于部分 ID 查找元素
我正在尝试使用硒从网站上获取一些天气数据。在 html 文件中,它们看起来像这样: 我正在尝试使用硒从网站上获取一些天气数据。在 html 文件中,它们看起来像这样: <div id="tdatmo1-FFrad6Noeud-20240225-0700" name="tdatmo1-FFrad6Noeud-20240225-0700" class="container_value " . ><div class='box-offset'>10</div></div> <div id="tdatmo1-FFrad6Noeud-20240225-0654" name="tdatmo1-FFrad6Noeud-20240225-0654" class="container_value " . ><div class='box-offset'>9</div></div> <div id="tdatmo1-FFrad6Noeud-20240225-0648" name="tdatmo1-FFrad6Noeud-20240225-0648" class="container_value " . ><div class='box-offset'>7</div></div> ID 的前半部分始终相同,但后半部分根据时间/日期而变化。 我想我可以使用driver.find_elements(By.ID, "tdatmo1-FFrad6Noeud"),但这似乎不起作用。我也知道 By.XPATH 和 PARTIAL_LINK_TEXT,但我不确定它们是否适用于我的情况。 我查看了解决方案here 并尝试了driver.find_element(By.XPATH, "//*[contains(@id, 'tdatmo1-FFrad6Noeud')]"),这给了我<selenium.webdriver.remote.webelement.WebElement (session="007ad7b2-c5ba-46a8-8f5b-cbe0ea396b55", element="1c616c23-d457-4799-9c20-5a831d2895f1")> 我不确定这是否给了我想要的东西,而且它绝对不是我能理解的形式。 你可以点击它给你的没有headless的元素,然后看看它是否是。 webdriver.click()
有没有办法从典型的ajax函数中获取响应,以便可以用getElements对其进行剖析?我尝试过 query.responseText.getElementById 但它的效果和看起来一样糟糕。你...
未捕获类型错误:无法读取 null 的属性(读取“值”)getElementById
单击按钮时出现此错误。 未捕获的类型错误:无法读取 null 的属性(读取“值”) 我究竟做错了什么?这是代码: 单击按钮时出现此错误。 未捕获的类型错误:无法读取 null 的属性(读取“值”) 我做错了什么?这是代码: <table> <tr> <th>Height (inches)</th> <th>Width (inches)</th> <th>Length (inches)</th> <th>Pieces</th> <th>Bd Ft</th> <th>Lineal Ft</th> <th>Sqare Ft</th> </tr> <tr> <td> <input type="text" value="1" id="height" /></td> <td> <input type="text" value="1" id="width" /></td> <td> <input type="text" value="1" id="length" /></td> <td> <input type="text" value="1" id="pieces" /></td> <td> <input type="text" value="" id="bdft" /></td> <td> <input type="text" value="" id="linealft" /></td> <td> <input type="text" value="" id="sqft" /></td> </tr> </table> <input type="button" value="Calculate" onclick="calculate()" /> <script type="text/javascript"> function calculate() { var heightVar = document.getElementById(height); var widthVar = document.getElementById(width); var lengthVar = document.getElementById(length); var piecesVar = document.getElementById(pieces); alert(document.getElementById(height).value); } </script> 我做错了什么?我希望在警报窗口中获得“高度”值。 我缺少引文(废话)。 var heightVar = document.getElementById(height); 需要 var heightVar = document.getElementById("高度");
js for 循环innerHTML 函数在加载相同id 时不起作用
for循环innerHTML +=不起作用 富巴 document.getElementById('outSecs').</desc> <question vote="-1"> <p>在 addeventlistener 负载上调用函数时,for 循环 insideHTML += 不起作用</p> <pre><code><main id='outSecs'> foobar </main> <script> document.getElementById('outSecs').addEventListener('load', myFn); function myFn() { for (var q = 1; q <= 9; q++) { document.getElementById('outSecs').innerHTML += "<section><p class='myOutput'></p></section>"; } } </code></pre> <p>如何在加载时插入带有innerHTML的循环代码?</p> </question> <answer tick="false" vote="0"> <p>我建议你使用窗口的 DOMContentLoaded 事件。</p> <p>代码也可以更优雅。无需每次都获取主容器。只需获取一次并填充即可。</p> <p></p><div data-babel="false" data-lang="js" data-hide="false" data-console="true"> <div> <pre><code>const myFn = () => { const mainContainer = document.getElementById('outSecs'); mainContainer.innerHTML = Array.from({ length: 9 }) .map((_, i) => `<section id="s${i}"><p class="myOutput">${i+1}</p></section>`) .join('') }; window.addEventListener('DOMContentLoaded', myFn)</code></pre> <pre><code><main id='outSecs'> foobar </main></code></pre> </div> </div> <p></p> </answer> </body></html>
我有一个输入,我想接收任何数字(不管它是否为负数、浮点数、长整型),我将其编码为现在允许 null、未定义或空值,但如果我输入 0,它将被读取为空 常量
为什么 getElementByID 返回 Nothing 而不是 NULL
在 VBA 中,如果我使用 getElementByID("id_name") 并且 id 不存在,则该函数不会返回任何内容,而不是 null。这让我不知道 DOM 是否尚未渲染该元素,或者 el...
javascript 循环和使用参数设置 documentGetElementById 的问题
我正在研究星级评级系统。我想在星星图像列表上设置事件侦听器,以便单击星星可以用实心或空白星星填充星星。问题是当
大家 我创建了一个项目模型,使管理员能够创建单独的项目并管理它们,其中每个项目都有自己的流程,因为它们的结构相似且不同......
javascript 使用一个 getElementById 多次随机数
我想在跨度 ID 中多次使用随机数结果 但即使克隆或委托结果也只会在结果中出现一次,而其他结果则显示为空白 我不知道该怎么做,他可以吗...
HTML 上的 document.getElementById 出现 Null 错误
函数 myFunction() { 变量名称=“”; var 密码 = ""; name = document.getElementById('name');...</desc> <question vote="-1"> <pre><code><body> <script lang="javascript"> function myFunction() { var name = ""; var password = ""; name = document.getElementById('name'); password = document.getElementById('password'); alert(name) alert(password) } </script> <h1 id="Center">Log in</h1> <input type="text" id="Center" id="name" style="background-color: rgb(255, 255, 255); border-radius: 0px;"> <input type="text" id="Center" id="password" style="background-color: rgb(255, 255, 255); border-radius: 0px;"> <input type="button" id="Center" style="width: 170px;" onclick="myFunction()" value="Submit"> </body> </code></pre> <p><pre><code>I want to make the input text to alert and I get data of text using a document.getElementById and there has a two text and one button and id center is the code that the object can go to the center place on the screen.</code></pre></p> <p>我试着把它串起来或者再写一次,但没有办法做得好。</p> </question> <answer tick="false" vote="0"> <p>尝试这样:</p> <p></p><div data-babel="false" data-lang="js" data-hide="false" data-console="true"> <div> <pre><code><!DOCTYPE html> <html> <head> <style> #Center { display: block; margin: auto; } </style> </head> <body> <script lang="javascript"> function myFunction() { var name = ""; var password = ""; name = document.getElementById('name').value; password = document.getElementById('password').value; alert("Name: " + name + "\nPassword: " + password); } </script> <h1 id="Center">Log in</h1> <input type="text" id="name" style="background-color: rgb(255, 255, 255); border-radius: 0px;" placeholder="Enter your name"> <input type="password" id="password" style="background-color: rgb(255, 255, 255); border-radius: 0px;" placeholder="Enter your password"> <input type="button" id="Center" style="width: 170px;" onclick="myFunction()" value="Submit"> </body> </html></code></pre> </div> </div> <p></p> </answer> </body></html>
javascript getelement,其中值包含特定字符串
我想计算具有文本类名称的输入字段的出现次数,其中该文本输入包含特定值。 document.getElementById('c_files').getElementsByClassName('tex...
如果我知道的是这个文本:8039089332,我该如何提取文本:mytr161 如果我所知道的文本是:8039089332,我该如何提取文本:mytr161 <tr bgcolor="#dcdcdc" id="mytr161"> <td align="right" bgcolor="#BDB9B4"><input type="checkbox" id="ck161" name="ck161" value="1" onclick="javascript:changebgcolor('161');"></td> <td align="center" nowrap=""><small><font size="2"> <a href="MfSchOpen850PODetail.asp?lpo=8039089332&litem=hidingit&Plant=hidingitaswell&lsimplifyordertype=hidden" target="Podetail">8039089332</a> </font></small> </td> 我有一个数字列表,如文本:8039089332。我想单击它旁边的复选标记。为此,我正在考虑如何编写一段javascript代码来循环遍历数字列表,然后单击复选标记,我认为,首先需要找到文本的id:8039089332。然后可能找到一种方法来修剪id删除文本“mytr”并将其替换为“ck”。 这是我第一次尝试 javascript,我现在不知道该怎么做,因为我无法提取我拥有的数字列表的 id。 //获取距离按钮最近的元素 varclosestTR=button.closest('tr'); //获取最近的id属性 var trId = 最接近的TR.id; // 用提取的 id 做一些事情(例如,将其记录到控制台) console.log('TR ID:', trId);
我必须多次使用我的脚本与 document.getElementById("")
我正在制作一个布局,其中每个框都必须使用... id =“top1”,id =“top2”,id =“top3”等...这样当您单击它时,它就会转到文档顶部,但我找不到...
getElementById 在 Javascript 页面构建中返回 null
我用javascript创建了结构。我不使用html。 我有一个创建结构并返回根窗格的函数。 函数 createEmptyChartPane (chartId) { 让 divlem = 文档。
正在做一个项目。我需要 else 语句才能工作,但是当我点击提交按钮时,它只是重定向到“if” var 判断量 = document.getElementById('</desc> <question vote="0"> <p>正在从事一个项目。我需要 else 语句才能工作,但是当我点击提交按钮时,它只是重定向到“if”</p> <pre><code><head> <script> var judgmentAmount = document.getElementById('judgmentAmount'); var amountCollected = document.getElementById('amountCollected'); function judgmentCalc() { if( judgmentAmount - amountCollected < 10000 ) { window.open( 'http://afjudgment.com' ); }else { window.open( 'http://www.yahoo.com' ); } } </script> </head> <body> <h1>Application</h1> <p>I understand that this application neither obligates me to <b>Affirmative Judgment</b> nor does it obligate <b>Affirmative Judgment</b> to me.</p> <h3>Judgment Information</h3> <form> <span>Do you have a case number?</span> <input type="text" name="caseNumber" /> <span>Amount of Judgment</span> <input type="text" name="judgmentAmount" id="judgmentAmount" /> <span>Amount collected to date</span> <input type="text" name="amountCollected" id="amountCollected" /> <input type="submit" name="submitButton" onclick="judgmentCalc();" /> </form> </code></pre> </question> <answer tick="false" vote="0"> <p>您需要访问这些输入字段的值,而不是直接处理 <pre><code>document.getElementById()</code></pre> 返回的 dom 元素。您可以使用 <pre><code>input</code></pre> 属性获取 <pre><code>.value</code></pre> 的值。</p> <pre><code>var judgmentAmount = document.getElementById('judgmentAmount').value; var amountCollected = document.getElementById('amountCollected').value; </code></pre> </answer> <answer tick="false" vote="0"> <p>将变量移到函数内部,以便在函数执行时正确填充它们,并添加 DOM 元素的 .value 属性。</p> <p>试试这个:</p> <pre><code> function judgmentCalc() { var judgmentAmount = document.getElementById('judgmentAmount').value; var amountCollected = document.getElementById('amountCollected').value; if( judgmentAmount - amountCollected < 10000 ) { window.open( 'http://afjudgment.com' ); }else { window.open( 'http://www.yahoo.com' ); } } </code></pre> </answer> <answer tick="false" vote="0"> <p>您只是比较对象,您需要比较它们的值</p> <pre><code>var judgmentAmount = Number(document.getElementById('judgmentAmount').value); var amountCollected = Number(document.getElementById('amountCollected').value); </code></pre> <p>另外,在比较之前将它们转换为数字。</p> <pre><code>function judgmentCalc() { var judgmentAmount = Number(document.getElementById('judgmentAmount').value); var amountCollected = Number(document.getElementById('amountCollected').value); if( judgmentAmount - amountCollected < 10000 ) { window.open( 'http://afjudgment.com' ); }else { window.open( 'http://www.yahoo.com' ); } } </code></pre> </answer> <answer tick="false" vote="0"> <p>您将在此处获取 HTML DOM 元素:</p> <pre><code>var judgmentAmount = document.getElementById('judgmentAmount'); var amountCollected = document.getElementById('amountCollected'); </code></pre> <p>因此,在您的 <pre><code>judgementCalc</code></pre> 方法中,您需要获取这些元素的值:</p> <pre><code>function judgmentCalc() { // notice that we're using VALUE here: if( judgmentAmount.value - amountCollected.value < 10000 ) { window.open( 'http://afjudgment.com' ); }else { window.open( 'http://www.yahoo.com' ); } } </code></pre> </answer> <answer tick="false" vote="0"> <p>您需要根据元素的值进行操作:</p> <pre><code>function judgmentCalc() { var judgmentAmount = +document.getElementById('judgmentAmount').value; var amountCollected = +document.getElementById('amountCollected').value; if( judgmentAmount - amountCollected < 10000 ) { window.open( 'http://afjudgment.com' ); } else { window.open( 'http://www.yahoo.com' ); } } </code></pre> <p>var <pre><code>judgmentAmount = document.getElementById('judgmentAmount')</code></pre> 仅返回对 ID 为“judgmentAmount”的元素的引用。如果你想使用元素的值,你需要这样做:</p> <p><pre><code>var judgmentAmount = document.getElementById('judgmentAmount').value</code></pre>。 </p> <p>下一步是计算一些金额。您需要将 string 转换为 int (使用 <pre><code>+</code></pre> 运算符)</p> <pre><code>typeof judgmentAmount; // "string" typeof +judgmentAmount; // "number" </code></pre> <p><a href="https://jsfiddle.net/ova74kmh/" rel="nofollow">演示</a></p> </answer> <answer tick="false" vote="-1"> <p>请运行下面的脚本,它会正常工作:</p> <pre><code><head> <script> function judgmentCalc() { var judgmentAmount = document.getElementById('judgmentAmount').value; var amountCollected = document.getElementById('amountCollected').value; var exp = parseFloat(judgmentAmount) - parseFloat(amountCollected); if( exp < 10000 ) { window.open( 'http://afjudgment.com' ); } else { window.open( 'http://www.yahoo.com' ); } } </script> </head> </code></pre> </answer> <answer tick="false" vote="-1"> <p>您必须比较输入元素的值,请尝试以下操作</p> <pre><code>function judgmentCalc() { var judgmentAmount = document.getElementById('judgmentAmount').value; var amountCollected = document.getElementById('amountCollected').value; if( (judgmentAmount - amountCollected) < 10000 ) { window.open( 'http://afjudgment.com' ); } else { window.open( 'http://www.yahoo.com' ); } } </code></pre> <p>它可能对你有帮助。</p> </answer> </body></html>
我使用 Visual Studio 2022 样板项目制作了 Blazor 服务器端 Web 应用程序。我仍在使用 .NET 7,因为我的公司更新速度很慢。 我已经按照本教程使用 JSIn...