【问题标题】:Browser issue :Branching Select Drop Down Not Supporting in IE 7 or 8浏览器问题:在 IE 7 或 8 中不支持分支选择下拉菜单
【发布时间】:2013-06-11 08:41:26
【问题描述】:

我有一个在 IE 版本 7 和 8 中不工作但在所有其他浏览器中工作的分支下拉菜单。

这是现场演示的 js Fiddle 链接:http://jsfiddle.net/r64w7/

我的代码:

HTML:

<div>
    <label >Select a step</label>
    <select id="selectCreateNew">
            <option value="input">
                    Input
            </option>
            <option value="radio">
                    Radio
            </option>
    </select>
</div>
   <div id="section1" style="display:none;">
      <label >Input</label>
      <input name="" type="text"/>
    </div>
   <div id="section2" style="display:none;">
         <label >Radio</label>
         <input name="" type="radio" value=""/>
   </div>

javascripts

var sections ={
'input': 'section1',
'radio': 'section2',
};

 selection = function(select) {

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

  }

  document.getElementById('selectCreateNew').addEventListener('change', function() {

  selection(this); 
try{for(var lastpass_iter=0; lastpass_iter < document.forms.length; lastpass_iter++)
   { var lastpass_f = document.forms[lastpass_iter];
     if(typeof(lastpass_f.lpsubmitorig2)=="undefined")
   { lastpass_f.lpsubmitorig2 = lastpass_f.submit; lastpass_f.submit = function()
     { var form=this; var customEvent = document.createEvent("Event");
          customEvent.initEvent("lpCustomEvent", true, true);
          var d = document.getElementById("hiddenlpsubmitdiv");
          for(var i = 0; i < document.forms.length; i++)

          { if(document.forms[i]==form){ d.innerText=i; } }
          d.dispatchEvent(customEvent); 
          form.lpsubmitorig2(); } } }}catch(e){}

  });

我在 java 脚本和 jQuery 方面真的很差。我从我的另一篇文章中得到这个。我没有弄清楚他不在 IE 7 和 8 中工作的问题。有什么方法可以在 IE 7 或 8 中完成这项工作。如果能支持 IE 7 那就太好了。

谢谢

【问题讨论】:

  • 您在问题中提到了 jQuery。该代码不是 jquery,但我强烈建议为此使用jquery,因为它会使代码更短,并且更有可能跨浏览器工作。
  • 谢谢,如果有的话,你能举个例子吗?对不起,我不擅长 jquery。
  • 是的,当然。把这个放在我身上。

标签: javascript html css cross-browser internet-explorer-7


【解决方案1】:

我知道这个问题没有被标记为 jQuery,但是在问题中提到了它,所以我觉得基于 jQuery 的答案是合适的,因为这实际上 非常 使用 jQuery 很容易。

这是您的 HTML 代码。我已经稍微修改了它 - 请注意选项的更改值和部分周围的额外包装 &lt;div&gt;

<div>
    <label >Select a step</label>
    <select id="selectCreateNew">
            <option value="section1">
                    Input
            </option>
            <option value="section2">
                    Radio
            </option>
    </select>
</div>
<div id='sections'>
    <div id="section1" style="display:none;">
       <label >Input</label>
       <input name="" type="text"/>
    </div>
    <div id="section2" style="display:none;">
         <label >Radio</label>
         <input name="" type="radio" value=""/>
    </div>
</div>

..和一些 jQuery 代码来做魔术:

$('#selectCreateNew').change(function() {
    var showme = $(this).val();
    $('#sections>div').each(function(i,e) {
        $(e).toggle(e.id === showme);
    });
});

是的,就是这么短。 :-)

Here it is as a jsFiddle

【讨论】:

  • 你太棒了 :) 在 IE 7 中工作得很好。非常非常感谢。
猜你喜欢
  • 1970-01-01
  • 2013-07-28
  • 1970-01-01
  • 1970-01-01
  • 2011-08-19
  • 1970-01-01
  • 1970-01-01
  • 2014-10-22
  • 1970-01-01
相关资源
最近更新 更多