私は、顧客のタイプに基づいてさまざまなフォームフィールドを非表示/再表示するように設計された非常に単純なスクリプトを持っています。コードは次のようになります。
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
ます。文字列がそのように編集される理由は何か考えられますか?
ありがとう!