DOCTYPE不能在Firefox中使用 [英] DOCTYPE not working in Firefox

查看:130
本文介绍了DOCTYPE不能在Firefox中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"         
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     <html>
    <head>
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Pragma"  content="no-cache">
    <meta http-equiv="Expires" content="-1">

        <Script language = JavaScript>
            function addOptionList(selectbox,text,value )
            {
                var optn = document.createElement('OPTION');
                optn.text = text;
                optn.value = value;
                selectbox.options.add(optn);
            }
            function removeOptionList(listbox,i){
                listbox.remove(i);
            }
            function addOption_list(fromvar,tovar){ 
                for(i=fromvar.options.length-1;i>=0;i--)    {
                    var userlist=fromvar;
                    if(fromvar[i].selected){
                        addOptionList(tovar, fromvar[i].value, fromvar[i].value);
                        removeOptionList(userlist,i);

                    }
                }
            }

        </Script>

    <table align='center'>
        <tr>
            <td ><select multiple name='userlist' id='userlist' >
                <option value='aaa'>aaa</option>
                <option value='bbb'>bbb</option>                
            </select></td>
            <td align='center' valign='middle'>
                <input value='--&gt;'  
                     onClick='addOption_list(userlist,pouser);' type='button'>
                <br><input value='&lt;--' 
                     onClick='addOption_list(pouser,userlist);' type='button'></td>
            <td><select multiple  name='pouser' id='pouser'>
                <option id='test' value='ccc'>ccc</option>              
            </select></td>
        </tr>
    </table>
</body>
</HTML>

我正在使用上面的代码从左边框中选择一个名称,并将其移动到右侧框中。该代码在IE / DOCTYPE下工作。但是当我使用DOCTYPE时,它在Firfox中停止工作。我花了很多时间,但仍然无法解决问题。另外,我是Javascript的新手,所以请用下面的代码解释我的问题(当我使用DOCTYPE时)。提前感谢您的帮助!

I am using the code above to select a name from left box and move it to the right box. The code is working in IE with/without DOCTYPE. But when I use DOCTYPE, it stops working in Firfox. I have spent a lot of time on it, but still couldn't figure out the problem. Also, I am a novice in Javascript, so please explain me the problem with code below (when I am using DOCTYPE). Thanks in advance for your help!!

推荐答案

您依赖于窗口上显示为全局属性的ID元素例如 userlist )。 Firefox只在quirks模式下才能做到这一点,这就是为什么doctype很重要。

You're relying on elements with ids showing up as global properties on the window (e.g. userlist). Firefox only does that in quirks mode, which is why the doctype matters.

这篇关于DOCTYPE不能在Firefox中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆