在網站開發項目中,常常會結合使用html,css,js,jquery,因爲常常會忘記如何添加關聯標籤,咱們會花費一些時間上網去找,影響開發效率。故在此進行一些總結。javascript
一、html中使用css的方法css
(1)、內聯樣式表html
內聯樣式表是在標籤內部使用css,雖然能到達到改變html樣式的目的,可是具備代碼看起來雜亂,修改不方便等缺點。java
例:jquery
<div data-for="result" style="height:0;width:0;overflow:hidden;" id="swfsocketdiv">內容</div>
其中的
style="height:0;width:0;overflow:hidden;
就是css代碼。ajax
(2)、嵌入樣式表api
嵌入樣式表是指css代碼嵌入到html中,通常是在一對<style>標籤內。dom
<style type="text/css">#ty_msg_mod *,#ty_msg_mod{margin:0px;padding:0px;}</style>
(3)、外部樣式表socket
外部樣式表的css代碼保存在單獨的文件中,經過一個<link>標籤來進行關聯。網站
<link type="text/css" charset="utf-8" rel="stylesheet" href="http://static.tianyaui.com/global/ty/resources/css/TY.ui.pop.css?_v=20150519">
二、html中使用JavaScript
(1)、內聯樣式表
例:
<td><button width="45" height="15" onclick=btn1()>按鈕1</button></td>
其中的 onclick=btn1()就是js語句。
(2)、嵌入樣式表
能夠寫在<head>或<body>中,在<head>中在頁面加載前執行,在<body>中則在頁面加載後執行。
例:
<script type="text/javascript"> var protocol = window.location.protocol; document.write('<script type="text/javascript" src="' + protocol + '//csdnimg.cn/pubfooter/js/repoAddr2.js?v=' + Math.random() + '"></' + 'script>'); </script>
(3)、外部樣式表
外部樣式表是單獨的js文件,經過<script>標籤進行關聯。
例:
<script src="http://139.129.220.86/js/jsstyle-yy.js"></script>
三、html中使用jquery
(1)、引用本地文件
與js第三種方式同樣。
<script type="text/javascript" src="scripts/jquery-1.5.2.min.js"></script>
(2)、引用公共庫文件
引用谷歌的,以下:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
引用百度的,以下:
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>