Javascript - 点击 [英] Javascript - onclick
问题描述
第一次在这里发帖,但上帝知道我一直在使用这个网站来搜索问题 :P 好吧,我现在遇到了自己的问题,我似乎无法轻松地在 Google 上搜索,玩了大约2个小时后,我终于决定发布一个问题,看看你们的想法.
我在这里想要完成的是,当您将鼠标悬停在 div 上时,它会出现一个按钮,单击该按钮会打开一个编辑窗格.该按钮正确显示在 div 上,但由于某种原因,我似乎无法使 onclick 功能发挥作用来挽救我的生命,哈哈.这是我正在使用的代码.如果还不够,请告诉我,我会再加一点酱汁.:P
function place_widget(name, properties){//bboxvar pleft = 属性 [0];var ptop = 属性[1];变量宽度 = 属性 [2];变量高度 = 属性 [3];var pright = pleft + 宽度;var pbottom = pleft + 高度;var bbox = [pleft, ptop, pright, pbottom];盒子[名称] = bbox;//身份证var id = 'widget_' + 名称;var editspanid = id + "_editspan";var editbuttonid = id + "_editbutton";var editpaneid = id + "_editpane";//创建元素var div = "对不起,丑陋的代码:P 有人知道为什么 onclick 功能不起作用吗?
另外,一些额外的信息:如果我打开 firebug 并放入:
document.getElementById('widget_Text_01_editbutton').onclick = alert;
当我点击按钮时,我得到:
未捕获的异常:[异常...对 WrappedNative 原型对象的非法操作"nsresult:0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)"位置:本机框架 :: <未知文件名> :: <TOP_LEVEL> ::第 0 行"数据:无]
我不确定这意味着什么.
谢谢!
解决方案 你能不能换个试试:
到:
另外,alert"是你写的函数吗?
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.
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);
}
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.
Thanks!
解决方案 Can you try changing:
<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 - 点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
相关文章
- WebDriver点击()vs JavaScript点击();
- Javascript点击功能;
- Applescript | Javascript - 使用Javascript点击链接?;
- 点击使用JavaScript记录;
- JavaScript点击事件问题;
- javascript - js点击事件;
- 模拟按钮点击javascript;
- PowerShell点击javascript链接;
- Javascript多点击事件;
- JavaScript:获取点击元素;
- 禁用多次点击JavaScript;
- Javascript 音频点击播放;
- 用javascript点击课程;
- 点击 Javascript 音频播放;
- 点击谷歌地图上的标记点击javascript api;
- javascript - jq的点击事件;
- javascript - 绑定点击事件;
- 在JavaScript内点击按钮;
- “点击"和"this"在JavaScript中;
- 使用curl点击javascript按钮;
- javascript touchend与点击困境;
- 通过JavaScript点击Flash对象;
- javascript - 点击数值累加;
- javascript - 关与遮罩点击!;
- Javascript注销点击后退按钮;
前端开发最新文章
- 为什么Chrome(在Electron内部)突然重定向到chrome-error:// chromewebdata?;
- 错误102(net :: ERR_CONNECTION_REFUSED):服务器拒绝连接;
- 如何解决'重定向已被CORS策略阻止:没有'Access-Control-Allow-Origin'标题'?;
- 如何处理“Uncaught(in promise)DOMException:play()失败,因为用户没有首先与文档交互。”在桌面上使用Chrome 66?;
- 警告:添加非被动事件侦听器到滚动阻塞'touchstart'事件;
- 如何在浏览器中播放.TS文件(视频/ MP2T媒体类型)?;
- 此请求已被阻止;内容必须通过HTTPS提供;
- 资源解释为样式表,但转换为MIME类型text / html(似乎与web服务器无关);
- 通过HTTPS加载页面但请求不安全的XMLHttpRequest端点;
- 拒绝从执行脚本'*',因为它的MIME类型(“应用/ JSON')不是可执行文件,并严格MIME类型检查被启用。;