web前端常用操作整理(含JS/HTML/CSS等方面知識(shí))
發(fā)布時(shí)間:2013-11-07 16:10:53 作者:佚名
我要評(píng)論
web前端包括JS、HTML、CSS等等方面,本文整理了前端的常用操作,善用可提高工作效率,個(gè)人感覺(jué)還不錯(cuò),喜歡的朋友可以參考下
取消 ul li 前面的圖標(biāo) 1
清空Value值 1
設(shè)置Value值 1
清空標(biāo)簽中間值 1
設(shè)置標(biāo)簽中間值 1
區(qū)分html()、text()、val()。 1
設(shè)置標(biāo)簽為可編輯狀態(tài) 1
設(shè)置標(biāo)簽為不可編輯狀態(tài) 1
兩個(gè)Ajax,一個(gè)A,一個(gè)B,B要在A執(zhí)行完畢之后執(zhí)行 2
時(shí)間間隔,只執(zhí)行一次,在指定的毫秒數(shù)后調(diào)用函數(shù)或計(jì)算表達(dá)式 2
時(shí)間間隔,執(zhí)行多次,每隔指定毫秒數(shù)后調(diào)用函數(shù)或計(jì)算表達(dá)式 2
jQuery全選/全不選/反選 2
Select-Optin項(xiàng) 3
讓DIV一直固定在屏幕的某個(gè)位置 4
取消 ul li 前面的圖標(biāo)
ul
{
list-style-type:none;
}
清空Value值
$("#city").val("");
設(shè)置Value值
$("#city").val("北京");
清空標(biāo)簽中間值
$("#ML1").html("");
設(shè)置標(biāo)簽中間值
$("#ML1").html("北京");
當(dāng)對(duì)某個(gè)標(biāo)簽再次加載值時(shí),常要先清除原有值
區(qū)分html()、text()、val()。
<input type="aaa" value="bbb">ccc</input>
text()輸出標(biāo)簽中間的內(nèi)容:1234。
val()輸出value屬性的值:bbb。
html()輸出整段html:<input type="aaa" value="bbb">ccc</input>。
val()的寫法針對(duì)jQuery
設(shè)置標(biāo)簽為可編輯狀態(tài)
$("input").removeAttr("readonly"); //所有input標(biāo)簽可編輯
$("textarea").removeAttr("readonly"); //所有textarea(部門簡(jiǎn)介)標(biāo)簽可編輯
$("input:button").removeAttr("disabled"); //所有button(左右框移動(dòng))標(biāo)簽不可編輯
設(shè)置標(biāo)簽為不可編輯狀態(tài)
$("input").attr("readonly", "readonly"); //所有input標(biāo)簽不可編輯
$("textarea").attr("readonly", "readonly"); //所有textarea(部門簡(jiǎn)介)標(biāo)簽不可編輯
$("input:button").attr("disabled", "disabled"); //所有button(左右框移動(dòng))標(biāo)簽不可編輯
兩個(gè)Ajax,一個(gè)A,一個(gè)B,B要在A執(zhí)行完畢之后執(zhí)行
由于Ajax是異步加載,各個(gè)Ajax幾乎同時(shí)執(zhí)行互不干擾,但有時(shí)我們要的效果是一個(gè)Ajax的請(qǐng)求要從另一個(gè)Ajax的返回值中取值,此時(shí),就會(huì)發(fā)生這種情況,解決方案有三個(gè):
1、 在名為A的Ajax的CallBack中寫名為B的Ajax請(qǐng)求;
2、 寫一個(gè)時(shí)間間隔函數(shù),監(jiān)聽(tīng)A的執(zhí)行,當(dāng)A執(zhí)行完畢之后,調(diào)用B;
3、 將Ajax的async設(shè)置為false,但這樣又通常要求全部都設(shè)置為false。
時(shí)間延遲,只執(zhí)行一次,在指定的毫秒數(shù)后調(diào)用函數(shù)或計(jì)算表達(dá)式
Var st o= setTimeout(到點(diǎn)要執(zhí)行的函數(shù)或表達(dá)式,延遲的毫秒單位時(shí)間);
window. clearTimeout(sto)使其失效,取消周期執(zhí)行
時(shí)間間隔,執(zhí)行多次,每隔指定毫秒數(shù)后調(diào)用函數(shù)或計(jì)算表達(dá)式
varstv= setInterval ("alert('間隔3000ms彈出一次!')",3000);
window.clearInterval(stv)使其失效,取消周期執(zhí)行
jQuery全選/全不選/反選
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>全選,不全選,反選</title>
<script src="jquery-1.7.1.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(function () {
$("#selectAll").click(function () {//全選
$("#ckList :checkbox").attr("checked", true);
});
$("#unSelect").click(function () {//全不選
$("# ckList:checkbox").attr("checked", false);
});
$("#reverse").click(function () {//反選
$("# ckList:checkbox").each(function () {
$(this).attr("checked", !$(this).attr("checked"));
});
});
});
</script>
</head>
<body>
<div id=" ckList ">
<input type="checkbox" value="值1" />值1
<input type="checkbox" value="值2" />值2
<input type="checkbox" value="值3" />值3
<input type="checkbox" value="值4" />值4
</div>
<input type="button" value="全選" id="selectAll" />
<input type="button" value="全不選" id="unSelectAll" />
<input type="button" value="反選" id="reverse" />
</body>
</html>
Select-Optin項(xiàng)
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
//所有
function All() {
var tt = $("#st")[0];
for (var i = 0; i < tt.length; i++) {
alert(tt[i].text);
}
}
//當(dāng)前所選
function Aselected() {
var tt = $("#st")[0];
for (var i = 0; i < tt.length; i++) {
if(tt[i].selected) {
alert(tt[i].text);
alert(tt[i].value);
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<select id = "st" multiple="multiple">
<option value="1">aaaaa</option>
<option value="2">bbbbb</option>
<option value="3">ccccc</option>
<option value="4">ddddd</option>
</select>
<input type="text" id = "tt"/>
<input type="button" onclick="All();" value="所有"/>
<input type="button" onclick="Aselected();" value="當(dāng)前所選"/>
</div>
</form>
</body>
</html>
讓DIV一直固定在屏幕的某個(gè)位置
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
#low_right
{
position: fixed;
width: 90px;
height: 90px;
background: #eee;
bottom: 40px;
right: 20px;
background-color: #DCFCE9;
border: 8px double #06F867;
text-align: center;
padding: 10px;
margin: 10px;
}
</style>
</head>
<body>
<script type="text/javascript">
for (var i = 0; i < 100; i++) {
document.write((i + 1) + "
");
}
</script>
<div id="low_right">
右下角
</div>
</body>
</html>
清空Value值 1
設(shè)置Value值 1
清空標(biāo)簽中間值 1
設(shè)置標(biāo)簽中間值 1
區(qū)分html()、text()、val()。 1
設(shè)置標(biāo)簽為可編輯狀態(tài) 1
設(shè)置標(biāo)簽為不可編輯狀態(tài) 1
兩個(gè)Ajax,一個(gè)A,一個(gè)B,B要在A執(zhí)行完畢之后執(zhí)行 2
時(shí)間間隔,只執(zhí)行一次,在指定的毫秒數(shù)后調(diào)用函數(shù)或計(jì)算表達(dá)式 2
時(shí)間間隔,執(zhí)行多次,每隔指定毫秒數(shù)后調(diào)用函數(shù)或計(jì)算表達(dá)式 2
jQuery全選/全不選/反選 2
Select-Optin項(xiàng) 3
讓DIV一直固定在屏幕的某個(gè)位置 4
取消 ul li 前面的圖標(biāo)
復(fù)制代碼
代碼如下:ul
{
list-style-type:none;
}
清空Value值
復(fù)制代碼
代碼如下:$("#city").val("");
設(shè)置Value值
復(fù)制代碼
代碼如下:$("#city").val("北京");
清空標(biāo)簽中間值
復(fù)制代碼
代碼如下:$("#ML1").html("");
設(shè)置標(biāo)簽中間值
復(fù)制代碼
代碼如下:$("#ML1").html("北京");
當(dāng)對(duì)某個(gè)標(biāo)簽再次加載值時(shí),常要先清除原有值
區(qū)分html()、text()、val()。
復(fù)制代碼
代碼如下:<input type="aaa" value="bbb">ccc</input>
text()輸出標(biāo)簽中間的內(nèi)容:1234。
val()輸出value屬性的值:bbb。
html()輸出整段html:<input type="aaa" value="bbb">ccc</input>。
val()的寫法針對(duì)jQuery
設(shè)置標(biāo)簽為可編輯狀態(tài)
復(fù)制代碼
代碼如下:$("input").removeAttr("readonly"); //所有input標(biāo)簽可編輯
$("textarea").removeAttr("readonly"); //所有textarea(部門簡(jiǎn)介)標(biāo)簽可編輯
$("input:button").removeAttr("disabled"); //所有button(左右框移動(dòng))標(biāo)簽不可編輯
設(shè)置標(biāo)簽為不可編輯狀態(tài)
復(fù)制代碼
代碼如下:$("input").attr("readonly", "readonly"); //所有input標(biāo)簽不可編輯
$("textarea").attr("readonly", "readonly"); //所有textarea(部門簡(jiǎn)介)標(biāo)簽不可編輯
$("input:button").attr("disabled", "disabled"); //所有button(左右框移動(dòng))標(biāo)簽不可編輯
兩個(gè)Ajax,一個(gè)A,一個(gè)B,B要在A執(zhí)行完畢之后執(zhí)行
由于Ajax是異步加載,各個(gè)Ajax幾乎同時(shí)執(zhí)行互不干擾,但有時(shí)我們要的效果是一個(gè)Ajax的請(qǐng)求要從另一個(gè)Ajax的返回值中取值,此時(shí),就會(huì)發(fā)生這種情況,解決方案有三個(gè):
1、 在名為A的Ajax的CallBack中寫名為B的Ajax請(qǐng)求;
2、 寫一個(gè)時(shí)間間隔函數(shù),監(jiān)聽(tīng)A的執(zhí)行,當(dāng)A執(zhí)行完畢之后,調(diào)用B;
3、 將Ajax的async設(shè)置為false,但這樣又通常要求全部都設(shè)置為false。
時(shí)間延遲,只執(zhí)行一次,在指定的毫秒數(shù)后調(diào)用函數(shù)或計(jì)算表達(dá)式
復(fù)制代碼
代碼如下:Var st o= setTimeout(到點(diǎn)要執(zhí)行的函數(shù)或表達(dá)式,延遲的毫秒單位時(shí)間);
window. clearTimeout(sto)使其失效,取消周期執(zhí)行
時(shí)間間隔,執(zhí)行多次,每隔指定毫秒數(shù)后調(diào)用函數(shù)或計(jì)算表達(dá)式
復(fù)制代碼
代碼如下:varstv= setInterval ("alert('間隔3000ms彈出一次!')",3000);
window.clearInterval(stv)使其失效,取消周期執(zhí)行
jQuery全選/全不選/反選
復(fù)制代碼
代碼如下:<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>全選,不全選,反選</title>
<script src="jquery-1.7.1.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(function () {
$("#selectAll").click(function () {//全選
$("#ckList :checkbox").attr("checked", true);
});
$("#unSelect").click(function () {//全不選
$("# ckList:checkbox").attr("checked", false);
});
$("#reverse").click(function () {//反選
$("# ckList:checkbox").each(function () {
$(this).attr("checked", !$(this).attr("checked"));
});
});
});
</script>
</head>
<body>
<div id=" ckList ">
<input type="checkbox" value="值1" />值1
<input type="checkbox" value="值2" />值2
<input type="checkbox" value="值3" />值3
<input type="checkbox" value="值4" />值4
</div>
<input type="button" value="全選" id="selectAll" />
<input type="button" value="全不選" id="unSelectAll" />
<input type="button" value="反選" id="reverse" />
</body>
</html>
Select-Optin項(xiàng)
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
//所有
function All() {
var tt = $("#st")[0];
for (var i = 0; i < tt.length; i++) {
alert(tt[i].text);
}
}
//當(dāng)前所選
function Aselected() {
var tt = $("#st")[0];
for (var i = 0; i < tt.length; i++) {
if(tt[i].selected) {
alert(tt[i].text);
alert(tt[i].value);
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<select id = "st" multiple="multiple">
<option value="1">aaaaa</option>
<option value="2">bbbbb</option>
<option value="3">ccccc</option>
<option value="4">ddddd</option>
</select>
<input type="text" id = "tt"/>
<input type="button" onclick="All();" value="所有"/>
<input type="button" onclick="Aselected();" value="當(dāng)前所選"/>
</div>
</form>
</body>
</html>
讓DIV一直固定在屏幕的某個(gè)位置
復(fù)制代碼
代碼如下:<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
#low_right
{
position: fixed;
width: 90px;
height: 90px;
background: #eee;
bottom: 40px;
right: 20px;
background-color: #DCFCE9;
border: 8px double #06F867;
text-align: center;
padding: 10px;
margin: 10px;
}
</style>
</head>
<body>
<script type="text/javascript">
for (var i = 0; i < 100; i++) {
document.write((i + 1) + "
");
}
</script>
<div id="low_right">
右下角
</div>
</body>
</html>
相關(guān)文章

15 個(gè)為編程初學(xué)者準(zhǔn)備的網(wǎng)站(都是國(guó)外的一些網(wǎng)站)
今天的文章,我們將分享15個(gè)可以學(xué)習(xí)編程的網(wǎng)站,這些網(wǎng)站上提供了很多編程教程,圖書以及編程練習(xí),希望對(duì)你有用2024-11-02web開(kāi)發(fā)中的長(zhǎng)度單位小結(jié)
這篇文章主要介紹了web開(kāi)發(fā)中的長(zhǎng)度單位主要包括px,pt,em等,需要的朋友可以參考下2023-08-06網(wǎng)頁(yè)前端開(kāi)發(fā)的一些尺寸單位(px,rem單位)
px單位是絕對(duì)單位,一般用于pc端網(wǎng)頁(yè)開(kāi)發(fā),因?yàn)槭墙^對(duì)單位所以在移動(dòng)端上的使用體驗(yàn)并不是很好,rem它是描述相對(duì)于當(dāng)前根元素字體尺寸,是相對(duì)單位,它可以根據(jù)根元素的變換而2023-08-06WEB前端優(yōu)化必備js/css壓縮工具YUI-compressor詳解與集成用法
壓縮工具層次不窮,各有優(yōu)點(diǎn),選擇適合的壓縮工具為將來(lái)做項(xiàng)目開(kāi)發(fā)使用是一件很重要的事情?。≡谶@介紹YUI-compressor,需要的朋友可以參考下2023-06-21html,css,javascript是怎樣變成頁(yè)面的
瀏覽器是多進(jìn)程的,有瀏覽器主進(jìn)程,網(wǎng)絡(luò)進(jìn)程,渲染進(jìn)程,插件進(jìn)程等,在將html,css,javascript解析成一個(gè)頁(yè)面的時(shí)候,就需要多個(gè)進(jìn)程的分工合作2023-05-01- 本文為大家整理了常用的文件對(duì)應(yīng)的MIME類型,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-04-25
postman中form-data、x-www-form-urlencoded、raw、binary的區(qū)別介紹
這篇文章介紹了postman中form-data、x-www-form-urlencoded、raw、binary的區(qū)別,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-12-28網(wǎng)頁(yè)中使用Unicode字符的介紹(&#,\u等)
國(guó)際組織制定了可以容納世界上所有文字和符號(hào)的字符編碼方案,稱為Unicode,是通用字符集Universal Character Set的縮寫,用以滿足跨語(yǔ)言、跨平臺(tái)進(jìn)行文本轉(zhuǎn)換、處理的要求2021-11-27前端實(shí)現(xiàn)字符串GBK與GB2312的編解碼(小結(jié))
這篇文章主要介紹了前端實(shí)現(xiàn)字符串GBK與GB2312的編解碼(小結(jié)),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2020-12-02
告別硬編碼讓你的前端表格自動(dòng)計(jì)算的實(shí)例代碼
這篇文章主要介紹了告別硬編碼讓你的前端表格自動(dòng)計(jì)算,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-09-27



