내 jQuery 모바일 앱에서 사용자가 알람 수를 입력합니다. 하루에 알람 수를 입력하면 3, 사용자가 데이터를 저장하기 위해 저장 버튼을 클릭 할 때 시간에 대한 3 개의 입력 필드를 생성합니다. 입력 된 시간이 현재 시간과 동일하지 않도록 모든 생성 된 입력 시간 필드의 유효성을 검사해야하며 고유 한 시간이 필요합니다. 다음 코드로 해결했지만 문제는 사용자가 고유 한 시간을 "반복되지 않는 시간"으로 입력하면 true 값에서 false 값으로 변경되지만이 조건을 입력하고 실행하지 않음jQuery 모바일에서 고유하고 중복되지 않도록 입력 필드를 확인하십시오.
else if 존재 == 거짓 & & $ (this) .attr ('value')! = c urrentTime)을 직접 "한 번"변경하면 기존 값이 변경되었음을 코드에 알리기 위해 다시 저장 버튼을 클릭하고 DB에 알람 데이터 저장을 계속해야합니다.
이 문제를 어떻게 해결할 수 있습니까? 나는이 문제가 그냥 .attr('value')
의 사용 일 대신 .val()
을 위해 그것을 하도 시도 할 수 있다고 생각
<body>
<div data-role="page" id="Alarm">
<div data-role="header" ></div>
<div data-role="content" >
<form>
<input type="number" id="AlarmTimes"/>
<label for="AlarmTimes" > Number of alarms Per day </lable>
<div id="timeFields" style="display:none;" >
</div>
<div>
<input type="button" id="SaveBtn" value="Save Alarm "/></div>
</form>
</div>
</div>
</body>
자바 스크립트
var alarm_TimesNum;
var exist = true;
var ExistAlarmTimesArr = [];
$('#AlarmTimes').on('keyup' , function(){
alarm_TimesNum = $('#AlarmTimes').attr('value');
var timeFields = $('#timeFields');
if(timeFields.children().length != 0)
{
timeFields.empty();
timeFields.hide();
}
for(var i=1 ; i<= alarm_TimesNum ;i++)
{
timeFields.append($('<div class="ui-grid-a" ><div class="ui-block-a"> <input type="time" name="alarmTime" class="AlarmTime" /></div>'
+'<div class="ui-block-b" ><label for=" alarmTime" ><font size="5px" style="font- weight: normal;" class="Time_label"> Time:: </font></label></div></div>'));
timeFields.trigger('create');
}
timeFields.show();
});
db.transaction(getExistAlarmsTime,transError,transSuccess);
$('#SaveBtn').on('click',function(){
$('.AlarmTime').each(function(i){
if($(this).attr('value') == currentTime || $.trim( $(this).attr('value')).length ==0)
{
$('.Time_label').each(function(j){ if(j==i){ $(this).addClass('missing');} });
if(i==0){ alert('Enter time for alarm 1 '); }
else if(i==1){alert('Enter time for alarm 2 '); }
else if(i==2){alert('Enter time for alarm 3 '); }
}
else if($(this).attr('value') != currentTime && exist == true)
{
for(var k=0;k<ExistAlarmTimesArr.length;k++)
{
if($(this).attr('value') == ExistAlarmTimesArr[k])
{
$('.Time_label').each(function(j){ if(j==i){ $(this).addClass('missing');} });
if(i==0){alert('Enter Another Time for alarm 1 you have another alarm at this time '); }
else if(i==1){ alert('Enter Another Time for alarm 2 you have another alarm at this time '); }
else if(i==2){ alert('Enter Another Time for alarm 3 you have another alarm at this time '); }
exist = true;
break;
}
else { exist = false; }
}
}
else if (exist == false && $(this).attr('value') != currentTime )
{
$('.Time_label').each(function(j){ if(j==i){ $(this).removeClass('missed');} });
NotifTime = $(this).attr('value');
TimeArr[j] = NotifTime;
j= j+1 ;
count ++;
}
});
// save data in the DB
});
function getExistAlarmsTime(tx)
{
tx.executeSql("SELECT Time FROM AlarmTBL ",[],AlarmTimeExist,transError);
}
function AlarmTimeExist(tx,result)
{
for(var j=0;j< result.rows.length; j++)
{
var row = result.rows.item(j);
ExistAlarmTimesArr[j] = row['Time'];
}
}
도움을 주셔서 감사합니다.하지만 문제가 여전히 남아 있습니다. 저장 버튼을 다시 클릭하면 true 변수에서 false 값으로 변경됩니다. – user
제발 도와주세요. ?? – user
죄송합니다. 더 이상 할 수 없지만 많은 문제가 있습니다. – lalaland