Javascript - onclick [英] Javascript - onclick
问题描述
第一次在这里发帖,但是上帝知道我用这个网站一直在寻找问题:P嗯,我现在遇到了一个问题,我似乎无法轻易找到谷歌周围的搜索,在玩了大约2个小时后,我终于决定发一个问题,看看你们的想法。
first time posting here, but god know's I use this site to search for problems all the time :P Well, I'm having a problem of my own now that I can't seem to figure out easily searching around Google, and after playing with it for about 2 hours, I've finally decided to post a question and see what you guys think.
我想在这里完成的是当您将鼠标悬停在div上时,有一个显示在div上的按钮,当单击该按钮时,会打开一个编辑窗格。按钮正确显示在div上,但由于某种原因,我似乎无法使onclick功能工作以保存我的生活大声笑。这是我正在使用的代码。如果还不够,请告诉我,我会再添加一点酱。 :P
What I'm trying to accomplish here is to have a button that appears over a div when you hover over it that, when clicked, opens an editing pane. The button appears over the div correctly, but for some reason I cannot seem to make the onclick function work to save my life lol. Here's the code I'm working with. If it's not enough, please let me know and I'll add a little more sauce. :P
function place_widget(name, properties){
//bbox
var pleft = properties[0];
var ptop = properties[1];
var width = properties[2];
var height = properties[3];
var pright = pleft + width;
var pbottom = pleft + height;
var bbox = [pleft, ptop, pright, pbottom];
boxes[name] = bbox;
//ID's
var id = 'widget_' + name;
var editspanid = id + "_editspan";
var editbuttonid = id + "_editbutton";
var editpaneid = id + "_editpane";
//Creating Elements
var div = "<div id='" + id + "' class='widget' onmouseover='widget_hover(event);' onmouseout='widget_out(event);'>";
var editbutton = "<a id='" + editbuttonid + "' href='#'><img onclick='toggleEdit;' src='../images/edit_button.png'></a>";
var editspan = "<span id='" + editspanid + "' class='editspan'>" + editbutton + "</span>";
var editpane = "<span id='" + editpaneid + "' class='editpane'>:)</span>";
div += editspan + editpane + "</div>";
body.innerHTML += div;
//Configuring Elements
var editspanelement = document.getElementById(editspanid);
var editbuttonelement = document.getElementById(editbuttonid);
editbuttonelement.onclick = alert; //Does nothing.
var editpaneelement = document.getElementById(editpaneid);
var mainelement = document.getElementById('widget_' + name);
mainelement.style.left = (pleft + leftmost) + "px";
mainelement.style.top = (ptop + topmost) + "px";
mainelement.style.width = width;
mainelement.style.height = height;
getContentsAJAX(name);
}
对于丑陋的代码很抱歉:P任何人都知道为什么onclick功能不是工作?
Sorry for the ugly code :P Anyone have any idea why the onclick function isn't working?
另外,还有一些额外的信息:如果我打开萤火虫并放入:
Also, a bit of extra info: If I open up firebug and put in :
document.getElementById('widget_Text_01_editbutton').onclick = alert;
当我点击按钮时,我得到:
When I click the button, I get:
uncaught exception: [Exception... "Illegal operation on WrappedNative prototype object" nsresult: "0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)" location: "native frame :: <unknown filename> :: <TOP_LEVEL> :: line 0" data: no]
我不确定那是什么意味着离开。
I'm not exactly sure what that means off hand.
谢谢!
推荐答案
你能尝试改变吗? :
<img onclick='toggleEdit;' src='../images/edit_button.png'>
to:
<img onclick='toggleEdit();' src='../images/edit_button.png'>
此外,您所写的功能是警报吗?
Also, is "alert" a function you wrote?
这篇关于Javascript - onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!