我刚刚学完xml和xsd。我制作了第一个 xml 文档,我只是想确保我使用 xsd 正确验证它。
我的xml代码:
<?xml version="1.0" encoding="UTF-8" ?>
<user xmlns="http://localhost" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://localhost user.xsd">
<name>
<first>jack</first>
<last>hals</last>
</name>
<name>
<first>harry</first>
<last>potter</last>
</name>
</user>
Run Code Online (Sandbox Code Playgroud)
我的 xsd 代码:
<?xml vesion="1.0" encoding="UTF-8" ?><xs:schema xmlns:xs="http://WWW.W3.org/2001/XMLSchema" targetNamespace="http://localhost" xmlns="http://localhost" elementFormDefault="qualified">
<xs:element name="user" block="substitution" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="name" minOccurs="1" maxOccurs="5" block="substitution">
<xs:complexType>
<xs:sequence>
<xs:element name="first" type="xs:string" default="jack" minOccurs="1" maxOccurs="1" block="substitution" />
<xs:element name="last" type="xs:string" default="hals" minOccurs="1" maxOccurs="1" block="substitution" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
我尝试过在线验证器,它说:A pseudo attribute name is expected.
现在做什么?
我想使用 gif 图像制作鼠标效果,但问题是图像不是从头开始的。
html 代码:
<div style="width: 100px;height: 100px;background: red;" onclick="myFunction(this,event)"></div>
JavaScript 代码:
function myFunction(ele,e)
{
var x = e.clientX - 15;
var y = e.clientY - 15;
var effect = document.createElement("DIV");
effect.style.background="url('http://s12.postimg.org/piulwsk61/image.gif')";
effect.style.backgroundSize="100% 100%";
effect.style.width="75px";
effect.style.height="75px";
effect.style.zIndex="1";
effect.style.position="fixed";
effect.style.top=y;
effect.style.left=x;
ele.appendChild(effect);
setTimeout(function(){ele.removeChild(effect);},700);
}
Run Code Online (Sandbox Code Playgroud)
问题已解决:
javascript代码:
function myFunction(ele,e)
{
var x = e.clientX - 15;
var y = e.clientY - 15;
var effect = document.createElement("IMG");
effect.style.src="http://s12.postimg.org/piulwsk61/image.gif";
effect.style.width="75px";
effect.style.height="75px";
effect.style.zIndex="1";
effect.style.position="fixed";
effect.style.top=y;
effect.style.left=x;
ele.appendChild(effect);
setTimeout(function(){ele.removeChild(effect);},700);
}
Run Code Online (Sandbox Code Playgroud)
我不想在我的代码中使用jquery,所以在不使用jquery的情况下是否存在(或如何定义)javascript中的函数stopPropagation()?
我想在另一个for循环中使用for循环来获取xml文件的内容.问题是,当第二个循环开始时,第一个循环停止.
javascript代码:
var x = xmlDoc.getElementsByTagName('usr');
for (i=0; i <= x.length; i++) {
var y = x[i].childNodes;
for(n=0; n <= y.length; n++) {
var z = y[n].childNodes[0];
document.write(z.nodeValue);
}
}
Run Code Online (Sandbox Code Playgroud)
xml代码:
<usr><age>30</age><location>uk</location></usr>
<usr><age>25</age><location>usa</location></usr>
Run Code Online (Sandbox Code Playgroud)
输出是:
30uk
Run Code Online (Sandbox Code Playgroud)
它应该是30uk25usa