第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

求大神解釋下代碼,有點糾結(jié)

以下兩段JAVASCRIPT代碼(以橫線隔開好區(qū)分大神看下),都是同樣的效果,為何用第一段是單機即可實現(xiàn),第二段則需要雙擊呢(第二段A鏈接的那函數(shù)名我就不加了,那里都知道用來綁定函數(shù),那里大神不用解釋)


<!DOCTYPE html>

<html>

? ? <head>

? ? ? ? <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

? ? ? ? <title>挑戰(zhàn)題</title>

? ? ? ? <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>

? ? </head>

? ??

? ? <body>

? ? <ul>

? ? ? ? <li>001</li>

? ? ? ? <li>002</li>

? ? ? ? <li>003</li>

? ? ? ? <li>004</li>

? ? ? ? <li>005</li>

? ? ? ? <li>006</li>

? ? ? ? <li>007</li>

? ? </ul>

? ? <a href="javascript:;" >更多</a> ?

? ? </body>

? ? <script type="text/javascript">

? ? $("li:eq(4)").css("display","none");

? ? ? ? ? ? ? ? $("li:last").css("display","none");

? ? ? ? ? ? $(function(){

? ? ? ? $("a").click(function(){

? ? ? ? ? ? if($("a").text() === "更多"){

? ? ? ? ? ? ? ? $("a").text("簡化");

? ? ? ? ? ? ? ? $("li:eq(4)").css("display","list-item");

? ? ? ? ? ? ? ? $("li:last").css("display","list-item");

? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? $("a").html("更多");

? ? ? ? ? ? ? ? $("li:eq(4)").css("display","none");

? ? ? ? ? ? ? ? $("li:last").css("display","none");

? ? ? ? ? ? };

? ? ? ? ? ? });

? ? ? ? ? ? });

-------------------------------------------------------------------------------------------


$("li:eq(4)").css("display","none");

? ? ? ? ? ? ? ? $("li:last").css("display","none");

? ? ? ? ? ? function abc(){

? ? ? ? $("a").click(function(){

? ? ? ? ? ? if($("a").text() === "更多"){

? ? ? ? ? ? ? ? $("a").text("簡化");

? ? ? ? ? ? ? ? $("li:eq(4)").css("display","list-item");

? ? ? ? ? ? ? ? $("li:last").css("display","list-item");

? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? $("a").html("更多");

? ? ? ? ? ? ? ? $("li:eq(4)").css("display","none");

? ? ? ? ? ? ? ? $("li:last").css("display","none");

? ? ? ? ? ? };

? ? ? ? ? ? });

? ? ? ? ? ??

? ? ? ? ? ? };


? ? </script>

? ??

??


正在回答

1 回答

<!DOCTYPE html>

<html>

<head>

??? <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

??? <title>挑戰(zhàn)題</title>

??? <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>

</head>

<body>

??? <ul>

??????? <li>001</li>

??????? <li>002</li>

??????? <li>003</li>

??????? <li>004</li>

??????? <li>005</li>

??????? <li>006</li>

??????? <li>007</li>

??? </ul>

??? <a href="javascript:;" onclick="abc()">更多</a>

</body>

<script type="text/javascript">
??? $("li:eq(4)").css("display", "none");

??? $("li:last").css("display", "none");

??? function abc() {

??????? $("a").click(function () {

??????????? if ($("a").text() === "更多") {

??????????????? $("a").text("簡化");

??????????????? $("li:eq(4)").css("display", "list-item");

??????????????? $("li:last").css("display", "list-item");

??????????? } else {

??????????????? $("a").html("更多");

??????????????? $("li:eq(4)").css("display", "none");

??????????????? $("li:last").css("display", "none");

??????????? };
??????? });
??? };

</script>

</html>


這個是需要點擊兩次的代碼,如果你把$("a").click(function () {.....})這一層function去掉? 就可以實現(xiàn)點擊一次達到效果。

原因在于? <a href="javascript:;" onclick="abc()">更多</a>? 這個點擊事件觸發(fā)function abc() 當(dāng)該函數(shù)執(zhí)行到$("a").click(function ()? 這一步時,又需要觸發(fā)一次點擊事件? 才可以繼續(xù)調(diào)用該方法,讓程序往下進行。

1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

lihuwei 提問者

非常感謝!
2016-05-09 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消
jQuery基礎(chǔ)課程
  • 參與學(xué)習(xí)       154724    人
  • 解答問題       7289    個

加入課程學(xué)習(xí),有效提高前端開發(fā)速度

進入課程

求大神解釋下代碼,有點糾結(jié)

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號