0

我有一个问题,FireFox 3.6 不喜欢我在 jQuery (v1.7.2) 中调用非 jQuery 函数。

缩减我的代码版本:

function doInitialiseForm( theField ) {
  /* loop through a few fields and set the appropriate attributes & class */
  nX = parseInt( theField ) ;
  var inputElement = '' ;
  for ( i=(nX + 1); i <= 10 ; i++ )
  {
    $('#acBox' + i).addClass('pHide') ;  
    /* toggle the required attribute/class on the input boxes - for HTML5 input validation to behave correctly ... */
    inputElement =  document.getElementById('acBoxName_' + i ) ;
    inputElement.removeAttribute('required');
    $( inputElement ).removeClass( 'required' )
  }
}

$(document).ready(function() {

  if ( isBookingPage == '1' )
  {
      doInitialiseForm( document.getElementById('AttendingCount') ) ;  
  }
});

FireFox 报告的错误:

Error: uncaught exception: [Exception... "Not enough arguments"  nsresult: "0x80570001   (NS_ERROR_XPC_NOT_ENOUGH_ARGS)"  location: "JS frame :: http//development_server/Booking/js/script.js :: doInitialiseForm:: line 65"  data: no]

它似乎与 FF 期望第三个参数有关removeEventListener(),这是可选的。但是,我没有直接使用removeEventListener().

为了使上述代码在旧版本的 FireFox 中工作,我需要实现哪些额外的代码?

4

1 回答 1

0

问题现已解决。

函数 doInitialiseForm() 中省略的部分代码是调用 setAttribute() 并且我没有包含第二个参数。

即最初写为

inputElement.setAttribute('required');

什么时候应该

inputElement.setAttribute('required','');
于 2012-07-18T08:43:02.473 回答