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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Javascript 函數(shù)脫離了范圍?“X 不是函數(shù)” “X 是 ”“ ”

Javascript 函數(shù)脫離了范圍?“X 不是函數(shù)” “X 是 ”“ ”

我有一個(gè)JS函數(shù),該函數(shù)在單擊時(shí)調(diào)用,該函數(shù)傳遞一個(gè)字符串,并且第一個(gè)按鈕有效,但是所有后續(xù)按鈕都給我錯(cuò)誤action is not a function (In 'action("upvote")', 'action' is "")其中 action 是函數(shù)的名稱,upvote 是傳遞的變量。使用檢查元素向我顯示兩個(gè)按鈕是相同的,這是它們的外觀<button type="button" onclick="action('upvote')">Like</button>最奇怪的是按鈕在它調(diào)用函數(shù)之前,并且適用于所有按鈕,而不僅僅是第一個(gè)按鈕<button type="button" onclick="fun(84)">Reply</button>我檢查了,我沒有忘記關(guān)閉任何div或按鈕我唯一能想到的是,我通過(guò)遞歸php函數(shù)來(lái)回顯這些,我不認(rèn)為JS函數(shù)有范圍,但我不明白為什么第一個(gè)按鈕工作而不是后續(xù)如果需要更多代碼,請(qǐng)告訴我下面的代碼是我對(duì)父 divs 的打印函數(shù) echo "<div class='parent' style='margin-left:".$width."px'>".$x['comment']."    <div class='actions'>       <button  type='button' onclick='fun($ran)'>Reply</button>        <button type='button' onclick='action(\"upvote\")'>Like</button>         <button type='button'>Dislike</button>";    //Reply Like and Dislike are all actions every user gets, here I check which user it is to see if they can see the edit/delete    //Normally I would check for admin rather than id == 2, but there is only 1 admin and he id 2    if(($comment['userid'] == $_SESSION['id']) || $_SESSION['id'] == 2){         echo "<button type='button'>Edit</button>               <button type='button'>Delete</button></div>";//Close of actions div      }     else{        echo"</div>";//Close of actions div      }    $uname = mysqli_fetch_assoc($db->query("SELECT username FROM users WHERE id = ".$comment['userid']." "));    echo"    <div class='info'>    Score: ".$comment['score']." &nbsp; &nbsp; Posted By- ".$uname['username']."&nbsp; &nbsp At-".$x['created']." ";    if($x['edited'] != NULL){       echo"&nbsp; &nbsp; Edited Last-".$x['edited']." </div>";    }    else{       echo"</div>";    }?> </div> //Close of parent div這里仍然是我檢查注釋是否有任何回復(fù)注釋的函數(shù)的一部分,如果是這樣,我遞歸調(diào)用相同的函數(shù),
查看完整描述

1 回答

?
PIPIONE

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超9個(gè)贊

action中的內(nèi)聯(lián)事件處理程序引用包含單擊元素的窗體的屬性。它隱藏全局函數(shù),為函數(shù)使用不同的名稱,或者更確切地說(shuō),用于附加事件。您可以在代碼段中看到該值。actionactionaddEventListener


function foo(a) {

  console.log(a);

}

<form>

  <button type="button" onclick="foo(action);">

    Click

  </button>

</form>


這背后的原因是,內(nèi)聯(lián)處理程序中的代碼使用(或類似的內(nèi)部作用機(jī)制)限定為事件目標(biāo)元素,并且當(dāng)從元素本身找不到給定的變量(實(shí)際上的屬性)時(shí),請(qǐng)查找祖先元素,直到找到該屬性。如果未從元素中找到它,則要搜索的最后一個(gè)對(duì)象是 ,通過(guò)這種方式,它可以找到要執(zhí)行的全局函數(shù),前提是在升級(jí)到with (event.target) {...}windowwindow.


查看完整回答
反對(duì) 回復(fù) 2022-08-04
  • 1 回答
  • 0 關(guān)注
  • 113 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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