function addRole(val)
{
if (val == "ADD NEW")
{
$('#RoleModal').modal('show');
$('#form_role').validate({
rules: {
Storage Code: { required: true},
Storage Location: { required: true},
},
messages:{
Storage Code: {required: "This field is Required"},
Storage Location: {required: "This field is Required"}
}
});
}
}
这是我的JavaScript代码,但这会引发Javascript错误 ReferenceError:未定义addRole 虽然我定义了这个功能
这是我的观看代码
echo form_dropdown('Birth_Certificate_Storage_id['.$key.']', $optionstorage,"",array('class'=>'form-control roleId','id'=>'Birth_Certificate_Storage_id['.$key.']','onchange'=>'addRole(this.options[this.selectedIndex].text)'));
/* second line for readability */
答案 0 :(得分:2)
更正后的代码,使用带空格的字符串键的引号...
function addRole(val)
{
if (val == "ADD NEW")
{
$('#RoleModal').modal('show');
$('#form_role').validate({
rules: {
"Storage Code": { required: true},
"Storage Location": { required: true},
},
messages:{
"Storage Code": {required: "This field is Required"},
"Storage Location": {required: "This field is Required"}
}
});
}
}