是否可以在JavaScript函数中定义全局变量?
我想在其他函数中使用trailimage变量(在makeObj函数中声明).
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
var offsetfrommouse = [10, -20];
var displayduration = 0;
var obj_selected = 0;
function makeObj(address) {
**var trailimage = [address, 50, 50];**
document.write('<img id="trailimageid" src="' + trailimage[0] + '" border="0" style=" position: absolute; visibility:visible; left: 0px; top: 0px; width: ' + trailimage[1] + 'px; height: ' + trailimage[2] + 'px">');
obj_selected = 1;
}
function truebody() {
return (!window.opera && document.compatMode && document.compatMode != "BackCompat") ? …Run Code Online (Sandbox Code Playgroud) 对不起,如果这非常明显,但我不知道为什么这不起作用.
我正在尝试创建一个jsFiddle.但是,我似乎无法将任何javscript附加到任何元素.例如,onclick不会调用我的js函数.
它没有比这个小提琴更简单.我从W3编辑器中复制粘贴它工作得很好 - 点击按钮,获得警报!
<button onclick="myFunction()">Click me</button>
function myFunction() {alert("sss");}
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/tpip/NYkQN/2/
我在这里失踪了什么?