DOCTYPE not working in Firefox

孤人 提交于 2019-12-25 08:23:45

问题


     <!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>

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!!


回答1:


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.




回答2:


Your markup does not match the DOCTYPE. I.e. you are not using valid XHTML 1.0 markup.

Paste you code into the xhtml validator and it will show you what's wrong.



来源:https://stackoverflow.com/questions/10034190/doctype-not-working-in-firefox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!