나는 3 개의 변수 (textInput, type, rowID
)를 가진 addText()
함수를 가지고있다. var
키워드없이 선언했기 때문에 함수 외부에서 사용할 수 있습니다. 그런 다음함수는 다른 함수의 변수를 어떻게 사용합니까?
<td><input type="checkbox" name="CB" id="monitor_'+rowID+'"/></td>
내가 그 세 변수의 사용을 필요로이 기능이있다 :
function monitoring(rowID, number, type) {
var $check = $('#status_table #monitor_' + rowID);
$('#test').append($check);
if($check.is(':checked')) {
$.post('/request', {
inputText: number,
key_pressed: type
}).done(function (reply) {
if(reply == "on") {
$('#test').append("on");
} else {
$('#test').append("off");
}
});
}
return;
}
이 기능은 여기에 호출됩니다 :
$('#status_table #monitor_'+rowID).each(function(rowID, textInput, type){
monitoring(rowID, textInput, type);
});
나는이 길을 만들어 많은 체크 박스가
참고 : inputText
은 어딘가에 게시되는 변수입니다.
질문 :
이 변수 선택기를 호출하는 올바른 방법이 있나요?
$('#status_table #monitor_'+rowID)
난 (선택기 기능 및 모니터링 기능 모두에서) 코드들의 제 2 세트에서 두 변수를 통과 하는가?
어떻게 변수를 올바르게 전달합니까?
선택기가 정확합니까? 또는
$('#status_table #monitor_'+rowID).each(function(){})
을$('#status_table tr').each(function(){})
으로 변경해야합니까?
5. 추가 된 기능 : "모니터링"기능은 어디에 호출해야합니까? addText (아래 코드 참조) 아래에 넣었지만 "추가"단추를 클릭했을 때만 함수가 실행되기 때문에 의미가 없습니다. 또한, 내 선택기 변수로, 나는 그것이 실제로 확인 된 모든 확인란에 대해 동일한 일을 수행 할 수 있는지 확인하고 싶습니다. 내가 어떻게 할 수 있니?
확인란을 선택했을 때 시도했지만 내 코드가 전혀 응답하지 않습니다.
편집 :
다음의 내 addText()
기능 (위와 같이이 함수 대신 다른 jQuery를 동작에서 내가 포함 한 기능 모니터링) :
function addText(add_type, fb_type) {
$("#" + add_type + "Add").click(function() {
$('.TextInput').empty();
textInput = $("#" + fb_type + "TextInput").val();
if(textInput.length === 0) {
alert('please enter the fieldname');
return;
}
index = $('#status_table tbody tr').last().index() + 1;
type = $("#select-choice-1").find(":selected").text();
rowID = type + textInput;
var str = '<tr id="' + rowID + '">' + '<td>' + index + '</td><td>' + rowID +
'</td><td class="type_row_' + textInput + '">' + type + '</td><td class="feedback number">' +
textInput + '</td>' + '<td><img src="static/OffLamp-icon.png" class="image" id="off"></td>' +
'<td><input type="checkbox" name="CB" id="monitor_' + rowID +
'" class="custom" data-mini="true" /><label for="CB"> </label></td><td class="outputRemove">x</td>' +
'</tr>';
if(alreadyExist(textInput, type)) {
alert('Entry exists. Please enter another number.')
} else {
$('#status_table tr:last').after(str);
}
monitoring(rowID, textInput, type);
return;
});
}
테이블의 HTML :
<table class="config" id="status_table">
<thead>
<tr>
<th colspan="4" ; style="padding-bottom: 20px; color:#6666FF; text-align:left; font-size: 1.5em">Output Status</th>
</tr>
<tr>
<th>Index</th>
<th>Row ID</th>
<th>Feedback Type</th>
<th>Feedback Number</th>
<th>Status</th>
<th>Monitor?</th>
<th>Remove?</th>
</tr>
</thead>
<tbody>
<tr></tr>
</tbody>
</table>
먼저 질문을 마무리 할 수 있습니까? 당신이 틀린 이름을 가지고 있고, 물건을 빠뜨린 것처럼 보입니다. – Joseph
어느 것을 의미합니까? 필요한 경우 세부 정보를 추가 할 수 있습니다. – yvonnezoe
표의 HTML을 볼 수 있습니까? –