I have folks, 다음 테이블에있는 열의 색인을 확인해야하는 javascript 함수가 있습니다. 문제는 columnName과 테이블의 이름을 비교하는 것입니다. columnName 'ID'로 테스트했으며이 열은 테이블에 있지만 비교가 true가 아니므로 인덱스가 반환되지 않습니다.jquery로로드 한 문자열 비교
내 코드 :
function getColumnIndex(columnName, grid) {
console.log("loading column index for column: [" + columnName + "]");
$('div.hDivBox > table > thead > tr > th', grid).each(function(index) {
var name = $(this).attr('title');
console.log("Checking cell: [" + name + "]");
if (String(name) == columnName) {
return index;
}
});
console.log("no cell found with name: " + columnName);
return -1;
}
로그 문 : 컬럼에 대한
로드 열 인덱스 : [ID]
확인 전지 : [ID]
확인 전지 : [이름]
셀 검사 : [설명]
셀 검사 중 : [AddTime]
셀 검사 중 [UpdTime]
는 이름 찾지 셀 : ID
자바 스크립트 함수에 의해 분석되는 HTML의 예는 :
<div class="hDivBox">
<table cellspacing="0" cellpadding="0">
<thead>
<tr>
<th align="center" hidden="" axis="col0" title="ID" style="display: none;">
<div style="text-align: center; width: 30px;">ID</div>
</th>
<th align="center" axis="col1" title="Name" class="">
<div style="text-align: center; width: 250px;">Name</div>
</th>
<th align="center" axis="col2" title="Description" class="">
<div style="text-align: center; width: 250px;">Beschreibung</div>
</th>
<th align="center" axis="col3" title="AddTime">
<div style="text-align: center; width: 120px;">hinzugefügt</div>
</th>
<th align="center" axis="col4" title="UpdTime">
<div style="text-align: center; width: 120px;">aktualisiert</div>
</th>
</tr>
</thead>
</table>
'문자열 (이름)'은 이미 문자열이므로 전송하지 않아도됩니다. 또한 ID, 이름 및 제목에 대해 말할 때 반드시 확인하십시오. 모두 다른 속성입니다. –
이상한. 경우에, 나는'String (name) == String (columnName)'을 시도 할 것인데, 아무 것도 바꿀 것 같지 않다. –
가능한 [Javascript 함수가 요소를 반환하지 못함] (http://stackoverflow.com/questions)/11569516/javascript-function-return-element에 실패) – Bergi