JS创建HTML代码

Jessie丢 2013-11-29 09:17:34
var progressDis = document.createElement("span");
progressDis.className = "item_input";
//鼠标点击显示
progressDis.onclick = function () {
this.className += ' on';
};
//鼠标点击其他消失
progressDis.onBlur = function () {
this.className = this.className.replace(' on', ''); //鼠标一走的时候,把样式也去掉
};

其中鼠标点击执行事件了,鼠标点击其他事件(.onBlur)无反应。
...全文
213 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jessie丢 2013-12-18
  • 打赏
  • 举报
回复
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>1111</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type='text/javascript'> window.onload = function () { document.onclick = function (e) { e = e || window.event; var dom = e.srcElement || e.target; alert(dom.id); if (dom.id != "dialog" && document.getElementById("dialog").style.display == "block") { document.getElementById("dialog").style.display = "none"; } }; }; function openDialog(e) { document.getElementById("dialog").style.display = "block"; e = e || window.event; if (+'\v1') { e.stopPropagation(); } else { e.cancelBubble = true; } } </script> <style> #dialog { position:fixed; left:40%; top:100px; background-color:#ccc; width:200px; height:120px; display:none; } </style> </head> <body> <input type="button" value="打开" onclick="openDialog(event)" /> <div id="dialog"> 这是弹出层 </div> </body> </html>
Jessie丢 2013-12-02
  • 打赏
  • 举报
回复
没人帮忙吗?
Jessie丢 2013-11-29
  • 打赏
  • 举报
回复
引用 6 楼 laiyongxin 的回复:
你是想鼠标点击其他的时候 才把样式去掉 而不是鼠标离开的时候去掉样式 是不是? 如果是的话 你在onclick事件的时候 要把当前button传进去 并保存起来


var oldObj;
progressDis.onclick = function (button) {
    if(oldObj!=null){
         oldObj.className.replace('on', "")
    } 
    this.className += ' on';
    oldObj=button'
};
//描述 var progressDis = document.createElement("span"); progressDis.className = "item_input"; var progressDisI = document.createElement("i"); progressDisI.className = "tline hc"; var progressTexta = document.createElement("textarea"); progressTexta.className = "c_ccc"; progressTexta.style.resize = "none"; progressTexta.style.color="#666"; progressTexta.cols = 3; progressTexta.rows = 4; progressTexta.appendChild(document.createTextNode("图片描述...")); var oldObj; progressDis.onclick = function (progressTexta) { ; if (oldObj != null) { oldObj.className.replace(' on', "") } this.className += ' on'; oldObj = progressTexta; }; progressDis.appendChild(progressDisI); progressDis.appendChild(progressTexta); 这里的button传入progressTexta对吗?是不是这里出错了?
Jessie丢 2013-11-29
  • 打赏
  • 举报
回复
引用 6 楼 laiyongxin 的回复:
你是想鼠标点击其他的时候 才把样式去掉 而不是鼠标离开的时候去掉样式 是不是? 如果是的话 你在onclick事件的时候 要把当前button传进去 并保存起来


var oldObj;
progressDis.onclick = function (button) {
    if(oldObj!=null){
         oldObj.className.replace('on', "")
    } 
    this.className += ' on';
    oldObj=button'
};
按照你的写法 还是没实现,你的去除样式写在click里, 我鼠标点击其他时,无法触发这事件了,无法去除样式 是不是我哪里理解错了?求解
lyx266 2013-11-29
  • 打赏
  • 举报
回复
你是想鼠标点击其他的时候 才把样式去掉 而不是鼠标离开的时候去掉样式 是不是? 如果是的话 你在onclick事件的时候 要把当前button传进去 并保存起来


var oldObj;
progressDis.onclick = function (button) {
    if(oldObj!=null){
         oldObj.className.replace('on', "")
    } 
    this.className += ' on';
    oldObj=button'
};
Jessie丢 2013-11-29
  • 打赏
  • 举报
回复
求大师帮忙~~~
Im_Sorry 2013-11-29
  • 打赏
  • 举报
回复
引用 3 楼 dfjifjeiwqfjioewqpjf 的回复:
[quote=引用 1 楼 hou306010849 的回复:] progressDis.onBlur = function () { this.className.replace('on', ""); //鼠标一走的时候,把样式也去掉 };
我标注错了 我想实现 鼠标点击其他时,把样式去掉。[/quote] 用class
Jessie丢 2013-11-29
  • 打赏
  • 举报
回复
引用 1 楼 hou306010849 的回复:
progressDis.onBlur = function () { this.className.replace('on', ""); //鼠标一走的时候,把样式也去掉 };
我标注错了 我想实现 鼠标点击其他时,把样式去掉。
Jessie丢 2013-11-29
  • 打赏
  • 举报
回复
求帮助
Im_Sorry 2013-11-29
  • 打赏
  • 举报
回复
progressDis.onBlur = function () { this.className.replace('on', ""); //鼠标一走的时候,把样式也去掉 };

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧