2013-10-02 2 views
0

jquery의 새로운 내용. 기본적으로 내가하고 싶은 것은 사용자가 #modquote을 클릭하면 텍스트 영역이 비 었는지 여부를 확인합니다. 그렇지 않은 경우에는 확인 상자가 나타납니다. 사용자가 확인을 클릭하면 CANCEL을 수행하지 않으면 다음 단계 (9 행 이하)로 진행합니다. 내 문제는 사용자가 확인/취소를 클릭했는지 여부와 상관없이 확인 상자가 나타나면 발생합니다. jquery에서 확인 상자를 사용할 수 있는지, 아니면 어딘가에서 같은 코드를 놓칠 수 있는지 궁금합니다. 테스트 텍스트 영역에 확인 대화 상자를 결합jquery의 상자를 확인하십시오.

$('#modquote') 
    .click(function() { 
    var msgrep = $('textarea#modrepmsg').val(); 
    if (msgrep != '') 
    { 
     confirm("test?"); 
     return true; 
    } 
    var comment = $('#repmsg').val(); 
    var regex = /<br\s*[\/]?>/gi; 
    var quote = '>' + comment.replace(regex, "\n>") + '\n'; 
    //$("textarea#modrepmsg").html(comment.replace(regex, "\n ")); 
    //var quote = ">" + comment + "\n"; 
    //alert (quote); 
    //var count = comment.length; 
    $('textarea#modrepmsg').html(quote); 
}); 
+0

확인 결과를 테스트하지 않고 어쨌든 돌아 오는 중입니다. – melancia

+0

@MelanciaUK 나는 사용자가 확인을 클릭하면 자동으로 감지하고, 그렇다면 취소를 클릭하면 false를 반환하면 true를 반환합니다. – user2699175

+0

실제로 그렇게하지만 결과를 캡처하거나 테스트하지는 않습니다. – melancia

답변

1

도움을 주셔서 감사합니다 당신은 ...

$('#modquote') 
    .click(function() { 
    var msgrep = $('textarea#modrepmsg').val(); 
    if (msgrep != '' && confirm("test?")) 
    { 
     var comment = $('#repmsg').val(); 
     var regex = /<br\s*[\/]?>/gi; 
     var quote = '>' + comment.replace(regex, "\n>") + '\n'; 
     //$("textarea#modrepmsg").html(comment.replace(regex, "\n ")); 
     //var quote = ">" + comment + "\n"; 
     //alert (quote); 
     //var count = comment.length; 
     $('textarea#modrepmsg').html(quote); 
    } 
}); 
0

처럼, 비어 있지 그것의 아주 간단하고 이럴수 인 예는 여기 엔 사용의 작은 해킹 사용자 .If에서는 setTimeout은 경고 상자가 경고 상자 대신 코드 up.put 나타납니다 doesnt..then 휴가의 button..the 탭을 닫고 사용자의 경우 것입니다 클릭

var timeout; 
$(window).on('beforeunload', function(){ 
    timeout = setTimeout(function() { 
     alert('execute any function instead of me!!!!'); //all your validation stuff goes here 
    }, 1000); 
    return "exitinggggggggggggggggggggg"; 
}); 

sample fiddle

관련 문제