在winForm中使用webBrowser控件.但是当网页由Ajax或框架更新时,我无法使用
webBrowser1.document.getElementById等等来查找htmlElement.该元素也不会View->Source code在IE中显示.
其独特的目的是找到htmlElement并模拟点击或其他功能
invokeMember("staff").
我写了一个这样的svg文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="1280pt" height="650pt" viewBox="0 0 1280 650" id="svg1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"><script xlink:href="pathToPolyline.js"/><script><![CDATA[
alert(document);//returns [object SVG document]
//and tried
var path=document.getElementById('path1');//the problem line
alert(path);
]]></script>
<path id="path1" fill="#000000" d=" M 0.00 0.00 L 1280.00 0.00 L 1280.00 449.99 C 1276.46 444.19 1270.19 441.08 1265.59 436.31 C 1264.17 429.73 1265.36 422.91 1266.42 416.36 C 1267.19 413.43 1264.94 410.65 1262.45 409.42 C 1255.44 405.63 1247.99 402.68 12 .....
Run Code Online (Sandbox Code Playgroud)
如注释行中的alert(document);警报 …
我目前正在研究迁移到RichFaces 4.从我的JS,我必须使用DOM元素
document.getElementById('myParent:myElement').
Run Code Online (Sandbox Code Playgroud)
从JBoss迁移指南中,我了解到不能再使用"document.getElementById":https://community.jboss.org/wiki/RichFacesMigrationGuide33x-4xMigration-CommonComponentsChanges.
有人可以解释我为什么,我怎么能(简单地)将我对这个函数的所有调用 - 超过一千个 - 更改为其他东西?
谢谢.
这是我的一些代码...
$dom = new DomDocument;
$html = $newIDs[0];
$dom->validateOnParse = true;
$dom->loadHTML($html);
$dom->preserveWhiteSpace = true;
$tryID = $dom->getElementById('ID');
echo $tryID;
Run Code Online (Sandbox Code Playgroud)
我试图从一个网站上获取多个特定的ID,这仅显示一个,而且我在各处(包括在此处)都已经看到了这种方法,但是当我尝试打印出任何内容时,却没有任何显示。我尝试测试以查看它是否正在读取某些内容
if(!$tryID)
{
("Element not found");
}
Run Code Online (Sandbox Code Playgroud)
但它也从未打印出来。最后,我用过
echo $tryID->nodeValue;
Run Code Online (Sandbox Code Playgroud)
还是一无所有...有人知道我在做什么错吗?
另外,如果我确实可以正常工作,我可以在同一$ dom上以多种不同的方式读取不同的变量吗?如果这是有道理的。
发生了一些奇怪的事情,但我似乎无法document.getElementById在PHP内部使用JavaScript代码......
例如,将以下PHP代码(如下所示)加载到PHP文件中并运行它,没有JavaScript警报?但是,如果您复制PHP回显(或打印)的源代码并将其作为HTML文件运行,则会出现JavaScript警报?因此,在PHP标记内部创建的任何元素都不能在JavaScript中运行,即使JavaScript不在PHP标记之外?
这是PHP演示代码:
<?php
print "
<iframe id='my_id' name='my_id' src='http://www.php.com/'></iframe>
<SCRIPT LANGUAGE='javascript'>
document.getElementById('my_id').contentWindow.onload = function(){
alert('content loaded');
}
</SCRIPT>
";
?>
Run Code Online (Sandbox Code Playgroud)
如果这只是你的代码,它甚至不起作用:
<iframe id='my_id' name='my_id' src='<?php echo"http://www.php.com/"; ?>'></iframe>
<SCRIPT LANGUAGE='javascript'>
document.getElementById('my_id').contentWindow.onload = function(){
alert('content loaded');
}
</SCRIPT>
Run Code Online (Sandbox Code Playgroud)
这是出现的源代码(根据请求)(contentWindow.onLoad对于与我在Safari中不在同一域中的内容,它也正常工作):
<iframe id='my_id' name='my_id' src='http://www.php.com/'></iframe>
<SCRIPT LANGUAGE='javascript'>
document.getElementById('my_id').contentWindow.onload = function(){
alert('content loaded');
}
</SCRIPT>
Run Code Online (Sandbox Code Playgroud)
我的问题是在HTML中这段代码工作正常,警报被调用....在PHP中代码不起作用,警报永远不会被调用... PHP处理方式document.getElementById有问题,没有任何问题.contentWindow.onload.
有人可以解释document.getElementById("demo")下面的例子中的行吗?
我理解getElementById获取了demo的id,但id是在这段代码中<p id="demo"></p>究竟是<p id="demo"></p>做什么的?
document.getElementById("age") 很清楚,因为它获得了年龄的id作为输入.
function myFunction() {
var age,voteable;
age = document.getElementById("age").value;
voteable = (age < 18)? "Too young" : "Old enough";
document.getElementById("demo").innerHTML = voteable;
}Run Code Online (Sandbox Code Playgroud)
<p>Click the button to check the age.</p>
Age:<input id="age" value="18" />
<p>Old enough to vote?</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>Run Code Online (Sandbox Code Playgroud)
我是JavaScript的新手,所以请耐心等待.
我有以下代码:
<input id="test" name="test" type="text" value="" />
<input id="test" type="button" value="Go!" />
<script type="text/javascript">
window.location.href="http://www.thenewendurancefitness.com/" + document.getElementById('test').value;
</script>
Run Code Online (Sandbox Code Playgroud)
我希望代码只能在按下按钮时执行.该功能是将用户输入数据添加到URL的末尾,然后在按钮单击时,加载该URL.
截至目前,当我加载页面时,它会自动执行并转到URL.
我试图通过将我的 html 文档使用的 SVG 文件移动到对象标记中来使阅读体验更愉快。
SVG 的部分目的是使其可点击,从而改变其颜色。这是通过 JavaScript 完成的。
只要 SVG 位于父 html 中,一切就可以正常工作,但一旦我尝试使用对象标签,JavaScript getElementById 就会失败(console.log(svg_rectangle) 返回 null)。我假设 DOM 不再知道 SVG 元素一旦移动到对象标签中,所以它与范围有关?
谷歌搜索这个不太走运,我不是 DOM 专家,所以也许我没有使用正确的关键字。
我通过 Django 运行它,因此是 {{ STATIC_URL }}。
超文本标记语言
<html>
<body>
<object id="svg1" data="{{ STATIC_URL }}svg/test.svg" type="image/svg+xml"></object>
<!--
<svg
id="svg_square"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
height="256"
width="256"
version="1.1"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<g class="region">
<rect id="rect_front" transform="scale(1,-1)" height="64" width="64" y="-128" x="64" onclick="parent.testFunction(this.id)"/>
</g>
</svg>
-->
<script src="{{ STATIC_URL }}archive_140520/handle_svg.js" type="text/javascript"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
JavaScript
function testFunction(id){
console.log(id)
var svg_rectangle = document.getElementById(id);
console.log(svg_rectangle) …Run Code Online (Sandbox Code Playgroud) 我希望我的 JavaScript 在我创建的函数结束时等待七秒钟,然后刷新我的页面。如果它很重要,我在下面列出了 JavaScript 和 HTML 的重要部分......
JavaScript:
var textfill = function () {
var node = document.createElement("P");
var x = document.getElementById('entertext').value;
var textnode = document.createTextNode("The search results for: '" + x + "' will show up here");
node.appendChild(textnode);
document.getElementById("123").appendChild(node);
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<input type="text" id="entertext">
<input type="button" onclick="textfill()" value="Search">
<p id="123">
</p>
Run Code Online (Sandbox Code Playgroud) 我正在使用 Web2Py 将值列表发送到我的视图。
我的 HTML 是这样的:
<select id="DestinationOptions" onchange="SetDest(this)">
{{for key, value in dirList.iteritems():}}
<option name="DirListItem{{=key}}" id="{{=key}}"> {{=value}}</option>
{{pass}}
</select>
Run Code Online (Sandbox Code Playgroud)
我的 JavaScript 是这样的:
function SetDest(destComboBxID)
{
alert(destComboBxID.id);
var e = document.getElementById(destComboBxID);
var path = e.option[e.selectedIndex].value;
alert(path);
//document.cookie = "GD_"+file.id + "=" + file.id + ";";
}
Run Code Online (Sandbox Code Playgroud)
我只得到第一个alert(),然后在浏览器中调试时出现以下错误:
Uncaught TypeError: Cannot read property 'options' of null
Q:如何获取选中值的ID?
getelementbyid ×10
javascript ×8
html ×2
php ×2
svg ×2
ajax ×1
browser ×1
button ×1
c# ×1
document ×1
dom ×1
domdocument ×1
iframe ×1
nodevalue ×1
object-tag ×1
richfaces ×1
url ×1
user-data ×1