有人可以逐行解释我的意思吗?

时间:2018-07-29 13:43:43

标签: javascript

  1. 这是我的教程中的code.js
  2. 我的作业需要帮助:

        for (int k = 1; k < num; k++)
        {
            int j = i + j;
            int i = j - 1;
        }
    

2 个答案:

答案 0 :(得分:2)

我不想为您回答这个问题,因为这是您的作业,但是我可以为您指明正确的方向,以便您自己解决问题。

Document.getElementById文档是一个不错的起点。考虑传递给此函数的字符串(即“ toggle”)及其含义。

getElementById(id)返回的对象是Element。如果您仔细查看属性列表,应该会认识到那里提供的许多属性。

如果有任何卡住的地方,请记住,您始终可以在互联网上进行搜索。 MDN(我的链接所指向的网站)是了解这些事情的好地方。

答案 1 :(得分:0)

    var buttonRef2 = document.getElementById('toggle'); //Looking for an ID called 'toggle' on the page and assign it to the variable 'buttonRef2'

    buttonRef2.onclick = function () { //add onclick event to the previously declared variable so it can run the function 
    var state = document.getElementById('wikiList').style.display; //find the 'wikilist' ID's style.display property and assign it to variable 'state'. This way you save extra DOM search

    var txt = document.getElementById('toggle').textContent; //grab the textcontent from the element with the ID of 'toggle'and assign to txt varaible

    if(state == 'none' && txt == 'show' ) { //&& operator - checks if the block is hidden(none) and if the txt varaible has a value of 'show'
//if the above condition is met you are going to execute the next lines of code.
    document.getElementById('wikiList').style.display = 'block'; // change the css property of display to 'block' this will show the element if it's been hidden away
document.getElementById('toggle').textContent = 'hide'; // change the text of the toggle element to 'hide' 
document.getElementById('toggle').classList.add('extraStyle'); // add another css class called 'extraStyle' to the element with an ID of 'toggle'
    }
    else{ // else block if the above if statement criteria weren't met
    document.getElementById('wikiList').style.display = 'none'; // hide the 'wikilist' element
document.getElementById('toggle').textContent = 'show'; // change the text content to 'show' } }