Javascript函数在IE的onSubmit中不起作用。。。Firefox中没有错误 函数验证必填字段(formid){ var inputs=document.getElementsByClassName('required'); 对于(i=0;i

Javascript函数在IE的onSubmit中不起作用。。。Firefox中没有错误 函数验证必填字段(formid){ var inputs=document.getElementsByClassName('required'); 对于(i=0;i,javascript,internet-explorer,Javascript,Internet Explorer,>代码> GETelEntsByCaseNo.方法在Firefox 3和Safari 3.1中是新的,它在Internet Explorer中不存在,甚至在版本9 beta版本中也不存在。 < P>我会考虑使用jQuery function validateRequiredFields(formid) { var inputs = document.getElementsByClassName('required'); for(i=0;i<inputs.length;

>代码> GETelEntsByCaseNo.<代码>方法在Firefox 3和Safari 3.1中是新的,它在Internet Explorer中不存在,甚至在版本9 beta版本中也不存在。

< P>我会考虑使用jQuery

function validateRequiredFields(formid) {

    var inputs = document.getElementsByClassName('required');

    for(i=0;i<inputs.length;i++) {

        var FieldID = inputs[i].id;

        if( document.getElementById( FieldID ).value == '' ) {

           document.getElementById( FieldID ).style.border = '2px solid #FA3811';
           document.getElementById( FieldID ).style.background = '#FAA08E';
           document.getElementById( FieldID ).focus();
           return false;

        }

    }

    return true;
   }

我认为这也可以解决您的跨浏览器兼容性问题。

什么实际不起作用?函数不调用?您是否尝试过将alert()放入在validateRequiredFields方法的第一行?该函数实际上根本没有在IE中启动。我尝试了alertsHow您正在调用
validateRequiredFields
函数吗?提供的代码中没有任何指示。onSubmit=“return validateRequiredFields('form')”您知道
输入[I]==document.getElementById(FieldID)?你把事情弄得太复杂了。+ 1用于发现不支持的方法。考虑@ Burk的使用建议。我用标记名称获取元素,恢复到旧的方法。然而,我现在用一个空函数进行测试,只有一个警告,而我仍然一无所获。IE@AdamCoburn:发布更新的代码。
var inputs = $('.required',document);