从HTML表单中提取输入值时遇到一些问题.据我所知,我的代码没有任何问题,但我找不到问题所在.
<?php
error_reporting(E_ALL );
ini_set('display_errors', 1);
$t =<<<D
<form id="frm-send" method="post" action="index.php" >
<input type="text" name="data[postusername]" id="postusername" value="user" />
<input type="checkbox" name="data[save]" id="data[save]" value="1" />
<input type="hidden" name="secret" id="secret" value="0d35635c0cb11760789de6c4fe35e046311f724b" />
<input type="submit" name="btnSubmit" id="btnSubmit" value="Send" />
<input type="hidden" name="data[checkgetrequest]" value="true" id="data[checkgetrequest]" />
<input type="hidden" name="frm-id" value="13448477965028bfb44222d" id="frm-id" />
</form>
<input type="text" id="getfocus_txt_13448477965028bfb44222d" name="getfocus_txt_13448477965028bfb44222d" />
D;
$dom = new domDocument;
$dom->loadHTML($t);
$dom->preserveWhiteSpace = true;
$frmid = $dom->getElementById('frm-id') ;
echo $frmid->getAttribute('value');
?>
Run Code Online (Sandbox Code Playgroud)
它显示了一个错误:
Fatal error: Call to a member function getAttribute() …Run Code Online (Sandbox Code Playgroud) 我试图使用JavaScript来设置div的内部html,但由于某种原因,它无法正常工作.我发现其他人之前遇到过这个问题,但我在其他帖子中找到的解决方案都没有.我不明白什么是错的.
这是我的测试功能:
function test(){
document.getElementByID("test").innerHTML = "why won't you work";
alert("hello");
}
window.onload = test;
Run Code Online (Sandbox Code Playgroud)
正在调用该函数,因为如果注释掉document.getElementByID行,则警报框可以正常工作.如果没有注释该行,则它不起作用.我的控制台显示该行的错误:
TypeError: 'undefined' is not a function (evaluating 'document.getElementByID("test")')
Run Code Online (Sandbox Code Playgroud)
当然,我的页面正文中有一个id.
<div id="test"></div>
Run Code Online (Sandbox Code Playgroud)
我在网上发现的一切都说这应该有效.我搞不清楚了.任何帮助将不胜感激.
我有一个有效的XML文件,由以下.NET C#Windows服务读取.有问题的标签(u1_000)绝对在元素中:
<book id="u1_000" category="xyz">
Run Code Online (Sandbox Code Playgroud)
是否有某些原因GetElementById()找不到带有标记的Book元素?- 谢谢
XmlDocument doc = new XmlDocument();
doc.Load("C:\\j.xml");
XmlElement ee = doc.GetElementById("U1_000");
<book id="U1_000" category="web">
Run Code Online (Sandbox Code Playgroud) 这个问题可能看起来很愚蠢,但是使用document.getElementById("someId")Vs访问元素(使用id"someId")之间的区别是什么.只是输入someId?
例如:
document.getElementById("someId").style.top = "12px";
Run Code Online (Sandbox Code Playgroud)
VS
someId.style.top = "12px";
Run Code Online (Sandbox Code Playgroud)
这是一个示例代码http://jsfiddle.net/pRaTA/(我发现它在firefox中不起作用)
以下作品:
$ = document.form;
x = $.name.value;
Run Code Online (Sandbox Code Playgroud)
这不是:
$ = document.getElementById;
x = $("id").value;
Run Code Online (Sandbox Code Playgroud)
关于为什么这不起作用或如何做到这一点的任何想法?
我在我的html文档中有几个具有某些css类的div元素,并希望获得这些元素的x,y位置,在此先感谢.
当我尝试在chrome中运行此程序时,我继续收到错误"Uncaught TypeError:无法设置属性'innerHTML'为null".我现在不知道我做错了什么,而且任何帮助都会受到赞赏.
<!DOCTYPE html>
<html>
<head>
</head>
<script>
var x = "hey";
var counter = 1;
var button = document.getElementById("button");
var div = document.getElementById("box");
var text = document.getElementById("text");
var sound = document.getElementById("sound");
var array=[ "thanks for clicking", "keep on clicking", "click one more time", "why do you keep on clicking me?", "stop clicking me!"];
function thing(file){
var y = array[Math.floor(Math.random() * array.length)];
if (x == y){
while (y == x){
var y = array[Math.floor(Math.random() * array.length)];
}
}
form1.text.value=y;
x …Run Code Online (Sandbox Code Playgroud) 我正在使用下面给出的HTML页面的一部分,并想要提取div标签的内容,其id hiddenDivHL使用DOM Parser:
<div id='hiddenDivHL' style='display:none'>http://74.127.61.106/udayavaniIpad/details.php?home=0&catid=882&newsid=123069[InnerSep]http://www.udayavani.com/udayavani_cms/gall_content/2012/1/2012_1$thumbimg117_Jan_2012_000221787.jpg[InnerSep]??????????? ????????[OuterSep]
Run Code Online (Sandbox Code Playgroud)
到目前为止,我使用了以下代码,但我无法使用.getElementById如何做到这一点?
try {
URL url = new URL("http://74.127.61.106/udayavaniIpad/details_android.php?home=1&catid=882&newsid=27593");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName("item");
/** Assign textview array lenght by arraylist size */
name = new TextView[nodeList.getLength()];
website = new TextView[nodeList.getLength()];
category = new TextView[nodeList.getLength()];
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
name[i] = new TextView(this);
Element fstElmnt = …Run Code Online (Sandbox Code Playgroud) 我有这个代码:
document.getElementById(id).remove();
Run Code Online (Sandbox Code Playgroud)
但是,IE给我一个错误的功能.你知道另一种方法吗?
我正在尝试在vue组件中使用document.getElementById().scrollIntoView()来使用Jump-To-Div类型的功能.
如果我在组件中调用该函数,该功能可以正常工作.但是如果我尝试使用ref从父组件调用该函数,则该元素不会滚动到视图中.
父组件是页面,子组件是页面中的选项卡.
这是父组件中的子Vue组件: -
<el-tab-pane label="Solution Details" name="Solution Details" v-loading="loading">
<solution-details
:formData="response"
ref="solutionDetails"
@done="$emit('done')">
</solution-details>
</el-tab-pane>
Run Code Online (Sandbox Code Playgroud)
所以有一个SolutionDetails.Vue子组件,它有一个ref ="solutionDetails".我使用子组件的ref 在父组件中调用此方法:
handleClick(command) {
this.activeTab = 'Solution Details';
this.$refs.solutionDetails.showCurrent(command);
},
Run Code Online (Sandbox Code Playgroud)
子组件中有一个showCurrent函数,它应该为参数"command"执行.这是子组件中的该函数.
methods: {
showCurrent(index) {
document.getElementById(index).scrollIntoView();
},
Run Code Online (Sandbox Code Playgroud)
如您所见,showCurrent应该获取页面中的元素并应滚动到视图中.如果SolutionDetails.vue是活动选项卡,则相应的元素将完全滚动到视图中.但我正在从其他选项卡执行父函数,然后this.activeTab = 'Solution Details';正在执行,即.活动选项卡正在更改为SolutionDetails.vue,但请求的元素不会滚动到视图中.
当其他标签是activeTab时,我该怎么做才能滚动到一个元素?
getelementbyid ×10
javascript ×7
html ×5
dom ×4
android ×1
c# ×1
html5 ×1
innerhtml ×1
java ×1
php ×1
removechild ×1
variables ×1
vue.js ×1
xampp ×1
xml ×1