This code is not 运行 is google chrome,函数定义中出现语法错误

This code is not running is google chrome, get syntax error in function definition

function validateThisField(fieldID,fieldType="text"){

//var ID=fieldID.substr(fieldID.length - 1);

//var fieldSubName = fieldID.slice(0, -1);
var fieldVal = jQuery('#'+fieldID).val();
if(fieldType=="text" && fieldVal.length > 0){
    jQuery('#'+fieldID+'_lbl').addClass('errlabel');
    jQuery('#'+fieldID).removeClass('associate_error_border_radius');
}else{
    jQuery('#'+fieldID+'_lbl').removeClass('errlabel');
    jQuery('#'+fieldID).addClass('associate_error_border_radius');

This is html

`<input class="associate_error_border_radius" onblur="validateThisField('assoc_firstname_1');" name="assoc_firstname_1" id="assoc_firstname_1" type="textbox">`

此代码在 Mozilla 中是 运行,但在 google 中是 chrome 函数定义中出现语法错误。

您不能在 Javascript 中使用默认参数,因此您需要删除函数定义中的“="text"”

function validateThisField(fieldID,fieldType="text"){

function validateThisField(fieldID,fieldType){

查看此 SO post 了解更多信息 Set a default parameter value for a JavaScript function

如果您想在 javascript 中使用默认参数,请使用如下内容:

function foo(param){
    //'default' is the default value
    if(typeof param === 'undefined'){ param = 'default'; }
}