这是javascript中的一个参数
嘿,伙计们,我是javascript开发新手。我在javascript中看到了一些。代码是 html代码这是javascript中的一个参数,javascript,Javascript,嘿,伙计们,我是javascript开发新手。我在javascript中看到了一些。代码是 html代码 当我像这样写代码并用onclick=“someone(2,2)调用它时。它对我不起作用。为什么会这样。希望你们能帮助我。提前感谢这是指家长 因此: 了解这一点的最佳方法是使用本教程:您得到的错误是什么?“它对我不起作用”无论如何,您可能不应该使用onclick=。因为默认情况下,该窗口是这样传递的,但您可以编写:someone.call(this,2,2),当我使用第一个代码并使用oncli
当我像这样写代码并用
onclick=“someone(2,2)
调用它时。它对我不起作用。为什么会这样。希望你们能帮助我。提前感谢这是指家长
因此:
了解这一点的最佳方法是使用本教程:您得到的错误是什么?“它对我不起作用”无论如何,您可能不应该使用onclick=
。因为默认情况下,该窗口是这样传递的,但您可以编写:someone.call(this,2,2),当我使用第一个代码并使用onclick like onclick=”调用它时有人(这个,2,2)…它对我有用..但第二个选项不起作用这不是我的问题的答案,当您访问“this”时,您得到的是窗口对象而不是dombtw@woverton我想这个链接可能会帮助你理解你的问题:我需要知道为什么我的脚本在我替换domobject并使用这个关键字时无法工作。“DOM”和“window”是不同的全局变量。DOM是保存HTML的地方,“窗口”是存储javascript变量的地方
<table>
<tr>
<td style="width:70px;height:70px;background-color:white;" class="white" onclick="place(this,2,1)"></td>
<td style="width:70px;height:70px;background-color:black;" class="black" onclick="someone(this,2,2)"></td>
</tr>
</table>
<script type="text/javascript">
function someone(domobject,number,column){
if(domobject.style.backgroundColor=="black"||domobject.style.backgroundColor=="white")
domobject.style.backgroundColor="red";
else if(domobject.style.backgroundColor=="red")
domobject.style.backgroundColor=domobject.className;
}
</script>
function someone(number,column){
if(this.style.backgroundColor=="black"||this.style.backgroundColor=="white")
this.style.backgroundColor="red";
else if(this.style.backgroundColor=="red")
this.style.backgroundColor=this.className;
}
var Bacon = function(){
this.tasty = true;
this.burnt = false;
};
var b = new Bacon();
console.log(b.tasty); //True