尝试为表单提交计划一个字符串生成器:
try{
top.document.getElementById("attributes").contentWindow.location = "attributeToolbar.aspx?el_id=" + (t_selected.attr("id").match(intRegex)[0] || "new") + "&opts="+ form_to_server();
}catch(err){
alert(err);
//prints: TypeError: Unable to get value of the property '0': object is null or undefined.
}
我正在考虑将正则表达式与匹配项分开,如果没有匹配项,则将其分配给“new”以表明它不在 jquery 对象中。
上面语句中的关键区域是:
(t_selected.attr("id").match(intRegex)[0] || "new")
最佳答案
如果您只想测试匹配项,请执行以下操作:
... intRegex.test(t_selected.attr("id")) ...
相反。如果“匹配”调用返回 null
,数组索引运算符将给出该错误。
关于javascript - 尝试在 Javascript 中执行空合并运算符时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11037079/