0
我有一个解析的xml文件,显示两次相同的元素。现在我想要一个用onclick声明隐藏其中一个按钮的按钮。有谁知道如何做到这一点?删除已解析的元素onclick
<!DOCTYPE html>
<html>
<body>
<p id="dasa"></p>
<script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "customers.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x = xmlDoc.getElementsByTagName("syl");
document.getElementById("dasa").innerHTML =
x[0].getAttribute('category') + "<br>";
document.getElementById("dasa").innerHTML +=
x[0].getAttribute('category');
}
function remove() {
x[0].removeAttribute('category');
}
</script>
<button onclick="remove()">remove</button>
</body>
</html>
不幸的是,它不起作用。 –
@JandeVries我的代码是你的工作版本。你可能正在操纵你的xml响应完全错误,我不知道,因为你没有包含它。 –
它显示屏幕上的2个值,所以解析是好的,但按钮不起作用。 –