0
고객 유형에 따라 다양한 양식 필드를 숨기거나 숨기기 해제하도록 설계된 매우 간단한 스크립트가 있습니다. 코드는 다음과 같습니다jQuery - 이스케이프 된 문자열 변수?
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
이 삭제 된 것 같습니다. 문자열이 그런 식으로 편집되는 이유는 무엇입니까?
감사합니다. 큰 따옴표
시도 '$ ('# 고객-기능') .find하는 따옴표 안에 그것을 포함 ('입력 [데이터 기능 유형 : 그것은 기본적으로 정의 "+ field + '"]') .parent(). parent(). show();' –