开发者

HTML Javascript, checkbox toggles label and dropdown list visibility

I'm halfway to getting this correct, but i am currently stuck. Firstly i would like the label and dropdown to be hidden be defa开发者_如何学编程ult. This i have achieved using css:

#unis
{
    visibility:hidden;
}

The bit i am slightly stuck on is how to group the items, i have used:

<div class='row'>
    <div id = "unis">
        <label id='Universitylbl' for='University'>University institution:</label>
        <select name="uni">
            <option value="uni1">uni1</option>
            <option value="uni2">uni2</option>
            <option value="uni3">uni3</option>
            <option value="uni4">uni4</option>
            <option value="uni5">uni5</option>
        </select><br />
    </div>
</div>

and the javascript to toggle the visibility:

function toggle(elementID){
    var target1 = document.getElementById(elementID)
    if (target1.style.display == 'none') {
        target1.style.display = 'block'
    }
    else
         {
        target1.style.display = 'none'
    }
}

but the above code doesn't appear to work?


It seems you are assigning target2 a value and altering the display of target1. Shouldn't that be the same object ? (target, for example ?)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜