web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

jquery动态添加div标签,onclick事件方法无法执行(解决方法)

1107 ℃
     

问题描述:用jquery新增一个div弹窗,用onclick执行关闭无效应该怎么解决,下面web建站小编带大家如何正确打开方法!

代码如下:

document.writeln("<div id=\'trips\' style=\'position: absolute;left: 0;top: 0;width: 100%;height: 100%;background: rgba(0, 0, 0, .65);z-index: 10;\'>");
document.writeln("<div style=\'width:450px;position:fixed;left:50%;top:50%;margin:-150px -224px;background:#fff;\'>");
document.writeln("<h3 style=\'height:50px;line-height:50px;padding:0 20px;border-bottom:1px solid #ebebeb;margin:0;\'>温馨提示<img onclick=\'window.close();\' src=\'close.png\' style=\'width:20px;height:20px;cursor:pointer;float:right;position:relative;margin-top:15px;\'/></h3>");
document.writeln("</div>");
document.writeln("</div>");

解决方法:

把选先的onclick=\'close();\' 改成onclick=\'window.close();\'

接下来用原先的方法就可以关闭了!

function close() {
  $('#trips').hide()
}

html5有哪些常见的事件

简单介绍关于jquery的所有遍历方法

jquery如何实现鼠标点击页面出现水波纹效果

jquery关于交互的几种方式

jquery触发事件focus的运用

标签: jquery, onclick

上面是“jquery动态添加div标签,onclick事件方法无法执行(解决方法)”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_2835.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > js
本文共计758个字,预计阅读时长6分钟
生活小工具,收录了80多款小工具
上一篇: WordPress用自定义代码实现更高级的分页功能
下一篇: 车牌号输入HTML模板下载
x 打工人ai神器