HTML5和CSS3实例教程总结(推荐)

前端技术 2023/09/09 HTML

关于onclick的行为与内容分离

1.通过链接触发弹出窗口方式 (不推荐使用此方法!!!)

XML/HTML Code复制内容到剪贴板
  1. <a href=\'#\'    
  2.     onclcik = \"window.open(\'holiday_pay.html\',WinName,\'width=300, height = 300\');\">  
  3. Holiday Pay    
  4. </a>  

如果JS被禁用链接无法引导用户进入对应页面,不要为href属性赋\"#\"及类似的值

2.普通情况

XML/HTML Code复制内容到剪贴板
  1. <a href=\'holiday_pay.html\'    
  2.     onclcik = \"window.open(this.href,WinName,\'width=300, height = 300\');\">  
  3. Holiday Pay    
  4. </a>  

3.0  大量重复链接,为每个链接分配可识别类名,通过使用jQuery为每个click事件分别添加监听器

XML/HTML Code复制内容到剪贴板
  1. <a href=\"holiday_pay\" class=\"popup\">Holiday pay</a>  
  2.   
  3. var links = $(\"a.popup\");   
  4.   
  5. links.clcik(function(event){   
  6.    event.preventDefault();   
  7.    window.open($(this).attr(\'href\'));      
  8. });  

3.1  通多自定义数据类型设置弹出窗口尺寸大小 

XML/HTML Code复制内容到剪贴板
  1. <a href =\"holiday_pay.html\"  
  2.     data-width=\"600\"  
  3.     data-heigth = \"400\"  
  4.     title = \"Holiday Pay\"  
  5.     class = \"popup\"> Holiday pay </a>   
JavaScript Code复制内容到剪贴板
  1. $(function(){   
  2.    $(\".popup\").click(function(event){   
  3.        event.preventDefault();   
  4.        var href=$(this).attr(\"href\");   
  5.        var width = $(this).attr(\"data-width\");   
  6.        var height = $(this).attr(\"data-height\");   
  7.        var popup = window.open(href,\"popup\",\"height=\"+height+\",width=\"+width+\"\");   
  8. }) ;   
  9. });  

以上这篇HTML5和CSS3实例教程总结(推荐)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持phpstudy。

原文地址:http://www.cnblogs.com/liul0703/p/5677644.html

本文地址:https://www.stayed.cn/item/24226

转载请注明出处。

本站部分内容来源于网络,如侵犯到您的权益,请 联系我

我的博客

人生若只如初见,何事秋风悲画扇。