我有一个相当简单的脚本,旨在根据客户类型隐藏/取消隐藏各种表单字段。代码如下所示:
var customerTypeFields = [];
customerTypeFields['Individual'] = ['First Name(s)', 'Last Name', 'Date of Birth'];
customerTypeFields['Limited Company'] = ['Name', 'Company Number'];
customerTypeFields['Partnership'] = ['Name', 'Company Number'];
$('#customer-type-selector').chosen().change( function() {
var visibleFields = customerTypeFields[$(this).children("option[value='" + $(this).attr('value') + "']").text()];
console.log(visibleFields);
$.each(visibleFields, function(i, field) {
$('#customer-features').find('input[data-feature-type=' + field + ']').parent().parent().show();
});
});
这似乎在某种程度上有效,但是在加载个人时我遇到了一个奇怪的错误,即:
Uncaught Error: Syntax error, unrecognized expression: input[data-feature-type=First (s)]
您会注意到它First (s)
不在我的数组中,因此看起来这个词Name
被剥离了 - 知道为什么要这样编辑字符串吗?
谢谢!