我正在搞乱javascript,我注意到它不会加载特定的代码行。
这一个......
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib" : ["es2015.iterable.ts"],
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noEmitHelpers": true
},
"exclude": [
"node_modules",
"typings/main.d.ts",
"typings/main"
],
"filesGlob": [
"./src/**/*.ts",
"./test/**/*.ts",
"!./node_modules/**/*.ts",
"src/custom_typings.d.ts",
"typings/browser.d.ts"
],
"awesomeTypescriptLoaderOptions": {
"resolveGlobs": true,
"forkChecker": true
},
"compileOnSave": false,
"buildOnSave": false,
"atom": { "rewriteTsconfig": false }
}
function RoomClick(str, ID) {
RoomSelected();
_getRoomName = ID;
document.getElementById(_getRoomName).className = "RoomStyleSelected";
}
function RoomSelected() {
var divEls = document.getElementsByTagName("#Kati1 a")
var i = 0;
for (i = 0; i < divEls.length; i++) {
//alert(divEls[i].id);
_getRoomName = divEls[i].id;
document.getElementById(_getRoomName).className = "RoomStyle"; //part where it doesnt load.
}
}
function RoomClick(str, ID) {
RoomSelected();
_getRoomName = ID;
document.getElementById(_getRoomName).className = "RoomStyleSelected";
}
function RoomSelected() {
var divEls = document.getElementsByTagName("#Kati1 a")
var i = 0;
for (i = 0; i < divEls.length; i++) {
//alert(divEls[i].id);
_getRoomName = divEls[i].id;
document.getElementById(_getRoomName).className = "RoomStyle";
}
}
.RoomStyle {
position: relative;
width: 50px;
height: 30px;
float: left;
margin: 10px;
background-color: green;
border-radius: 5px;
font-family: 'Segoe UI';
font-size: 20px;
color: white;
cursor: pointer;
text-align: center;
}
.RoomStyleSelected {
position: relative;
width: 50px;
height: 30px;
float: left;
margin: 10px;
background-color: #00ff90;
border-radius: 5px;
font-family: 'Segoe UI';
font-size: 20px;
color: white;
cursor: pointer;
text-align: center;
}
#Kati1 {
position: relative;
top: 100px;
left: 20px;
width: 350px;
height: 250px;
border: solid 2px #00ff90;
border-radius: 10px;
}
这个剪辑显示了它实际发生的情况。当我想要它只是使所有绿色,然后只改变1的颜色..我怎么能这样做?
答案 0 :(得分:3)
Element.getElementsByTagName()
按标记名称选择元素,而不是通过CSS样式查询。
您正在寻找Document.querySelectorAll()
:
var divEls = document.querySelectorAll("#Kati1 a")