1

我有一个分支下拉效果(不确定名称)。我不擅长 javascript 和 jquery,但我可以修改很少。有了这些知识,我制作了这个效果。

你可以看到现场演示:http ://saifraihan.webege.com/Branching%20New/branching.html

这是我的:

HTML

<form id="survey" action="#" method="post">
    <div id="section">
            <label for="Select">Select a step</label>
            <select id="select" onchange="selection(this);">
                    <option value="none">
                            Input1
                    </option>
                    <option value="radio">
                            Radio1
                    </option>
            </select>
    </div>
    <div id="section2" style="display:none;">
            <input name="" type="text">
    </div>
    <div id="section5" style="display:none;">
            <p>
                    Radio Step 1<br/>
                    <label>
                            <input type="radio" name="RadioGroup2" value="radio" id="RadioGroup2_0">
                            Radio</label>
                    <br>
                    <label>
                            <input type="radio" name="RadioGroup2" value="radio" id="RadioGroup2_1">
                            Radio</label>
                    <br>
            </p>
    </div>
</form>

JS:

var sections ={
'none': 'section2',
'radio': 'section5'



};

var selection = function(select) {

 for(i in sections)
    document.getElementById(sections[i]).style.display = "none";    
    document.getElementById(sections[select.value]).style.display = "block";

}

此示例在 FF、Chrome 和 Opera 中运行良好。但问题是,它不适用于任何版本的 IE。我不知道为什么。由于我在 javascripts 方面很弱,我不知道为什么这不在 IE 中运行。有什么解决办法吗?如果可以,它会很棒。

提前致谢 。

4

1 回答 1

1

像这样绑定你的事件:

document.getElementById('select').addEventListener('change', function() { selection(this) });

这似乎在 IE (10) 中为我解决了问题。如果您需要支持 8 或更早版本:attchEvent在这些版本的 IE 中使用附加事件。因此,您还需要编写该逻辑(或者您可以使用 jQuery 或其他一些库来为您处理跨浏览器的内容)。

小提琴:http: //jsfiddle.net/jnuFq/2/

于 2013-06-13T20:41:40.260 回答