1

我正在尝试检查是否选中了复选框,如果选中,则在页面上显示一个元素。

这是我的功能:

function checkedTechSolutions(){    
    Y.one('#techsol input[type=checkbox]').on('change', function (e) {
        var target = e.currentTarget,
        techSBox = Y.one('#techsolutions');
        if (target.get('checked')){ 
            techSBox.show();
        } else techSBox.hide();
    }
}

这是我的CSS:

#techsolutions {width: 380px; height: 100px; background-color:#cee4f2; display: none;}
#techsolutions .box {text-align: center;} 

这是我的html:

<div id="techsolutions">

    <div class=box>
    <label for="TypeOfTS">Tech Solutions: </label>
    <select name="techSolutionsDrop">
        <option value="techServices">Choose your services </option>
    </select>
    </div>  

</div>
4

1 回答 1

1

一些注意事项:

  • 您的示例缺少复选框#techsol
  • 曾经checkedTechSolutions被叫过吗?使用 YUI 时,您不需要文档就绪类型事件来将侦听器附加到复选框。
  • 使用css 类来改变这样的视觉效果。它更容易理解和清洁。

看看这个jsfiddle中的完整解决方案

于 2013-05-21T06:28:56.980 回答