改变CSS“z-index”属性:“分配中的左侧无效” [英] Changing CSS "z-index" property: "Invalid left-hand side in assignment"
问题描述
我有一个元素onmouseover事件处理程序,它调用我做的一个假设改变另一个元素的css属性的函数,我给该元素的ID输出。当我把鼠标放在onmouseover处理程序的元素上时,我得到一个错误:Uncaught ReferenceError:在赋值中左侧无效。我认为我的功能有问题。我无法通过js更改元素的z-index?
I have an element with the onmouseover event handler which calls a function I made that is suppose to change the css property of another element and I gave that element the ID "output". As I place my mouse over the element with the onmouseover handler, I get an error: Uncaught ReferenceError: Invalid left-hand side in assignment. I think there's something wrong with my function. Am I not able to change the z-index of an element through js?
<!--My Css->
<style>
#output{
height:500px;
width:500px;
border: 1px solid black;
z-index:1;
}
</style>
<!--My Script-->
<script>
function ChangeZofO () {
document.getElementById("output").style.z-index="-1";
}
</script>
<!--My Html-->
<div id="MyDiv" onmouseover="ChangeZofO()"></div>
推荐答案
Javascript中的样式名称使用camelCase, :
Style names in Javascript use camelCase, so it should be:
document.getElementById("output").style.zIndex="-1";
-
是算术减法运算符不能在标识符中使用。
-
is the arithmetic subtraction operator, it can't used in identifiers.
这篇关于改变CSS“z-index”属性:“分配中的左侧无效”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!