2012-04-09 24 views
0

我創建上飛一個對話框,當我打開它的第一次它工作得很好,但是當我嘗試重新打開它再一次的功能點擊我創建不起作用。這是我的代碼,它全部在onready函數中。我只是試圖禁用一個輸入字段,並把它放在焦點上。非常感謝。jQueryUI的對話框重新打開輸入文本沒有被禁用

$("#rdoAddressN").click(function(){ 
    var html; 
    html="<table>" 
       +"<tr>" 
        +"<td style='font-size: 14px;' align='center'><strong>D I R E C T O R I O</strong></td>" 
       +"</tr>" 
       +"<tr>" 
        +"<td align='center' nowrap>" 
        +"<input name='zipcodeType' id='zipcodeTypeCP' value='1' type='radio' style='margin: 10px'><strong>CP</strong>" 
        +"<input name='zipcodeType' id='zipcodeTypeCol' value='2' type='radio' style='margin: 10px'><strong>Colonia</strong>" 
        +"<input name='btnBuscarCP' id='btnBuscarCP' value='Buscar' type='button' style='margin: 10px'>" 
        +"</td>" 
       +"</tr>" 
       +"<tr>" 
        +"<td align='center'>" 
         +"<input autocomplete='off' name='zipcodeDialog' id='zipcodeDialog' class='zipcodeDialog' size='50' class='authInput' type='text' disabled='disabled' />" 
        +"</td>" 
       +"</tr>" 
       +"<tr>" 
         +"<td >" 
          +"<div style='width: 576px; opacity: 0.999999; display: none;' id='divResultsCP' align='center'>" 
          +"</div>" 
         +"</td>" 
        +"</tr>"; 

     +"</table>"; 

    var caja2 = $('<div title="Direccion de Codigos Postales"><p>'+html+'</p></div>'); 
    caja2.dialog({modal: true,show: 'fade',hide: 'fade',height:'auto',width:'auto'}); 
    $(":button").button(); 
    $('#zipcodeTypeCP').click(function(){ 
     $('.zipcodeDialog').remove("disabled"); 
     $('.zipcodeDialog').attr("disabled", true); 
     $('.zipcodeDialog').attr("disabled", false); 
     $('.zipcodeDialog').focus(); 
    }) 
    $('#zipcodeTypeCol').click(function(){ 
     $('.zipcodeDialog').remove("disabled"); 
     $('.zipcodeDialog').attr("disabled", true); 
     $('.zipcodeDialog').attr("disabled", false); 
     $('.zipcodeDialog').focus(); 
    }) 
    $('#btnBuscarCP').click(function(){ 
      if($('#zipcodeDialog').val().length>3){ 
      $("#divResultsCP").html('<img src="img/ajax-loader-big.gif" />') 
      $.ajax({ 
       data: "texto="+ $('#zipcodeDialog').val()+"&zipcodeType="+$('input:radio[name=zipcodeType]:checked').val() , 
       type: "post", 
       dataType: "json", 
       url: "ajax/cp.php", 

       success: function(data){ 
         switch(data.error){ 
         case undefined: 
           if(data.mensaje==undefined){ 
            $("#autocomplete_choices").html(''); 
            var tabla="<table class='cptable'>"; 
            tabla+="<tr >" 
             tabla+="<td ></td>"; 
             tabla+="<td>CP</td>"; 
             tabla+="<td>Colonia</td>"; 
             tabla+="<td>Municipio</td>"; 
             tabla+="<td>Ciudad</td>"; 
             tabla+="<td>Estado</td>"; 
            tabla+="</tr>" 

            for(index=0; index<data.length; index++) { 
             tabla+='<tr><td><a href=""> + </a></td><td>' + data[index].postal_code + '</td><td> ' + data[index].colony_name + '</td><td>'+ data[index].d_mnpio+'</td><td>'+ data[index].city_name+'</td><td> '+data[index].state_name+'</td></tr>' 
            } 
            tabla+="<table>" 
           }else{ 
            tabla=data.mensaje; 
            $("#divResultsCP").addClass("ui-state-highlight"); 
           } 
           $("#divResultsCP").html(tabla) 
           $("#divResultsCP").show() 
          break; 
         case 'Login': 
           $("#autocomplete_choices").html(''); 
           alert("Usuario No logueado"); 
          break; 
         default: 
           $("#autocomplete_choices").html(''); 
           $("#divResultsCP").html(data.error); 
           $("#divResultsCP").addClass("ui-state-highlight"); 
          break; 
        } 
       } 
       ,error: function (request, status, error) { 
        alert(request.responseText); 
       } 


      }); 
     } 
    }); 

})` 
+0

請發表您的代碼或其他地區更好,但一個的jsfiddle。 – j08691 2012-04-09 15:22:30

+4

這太可怕了,有了那麼多的html,只需將html放在你的視圖上,然後使用jquery-ui的對話道具讓它不能在開始時顯示,並根據需要打開和關閉它 – SpYk3HH 2012-04-09 15:26:13

+0

http://jsfiddle.net/ maxing80/chQfL/ahi se ve el jsFiddle – maxing80 2012-04-09 17:10:42

回答

0

那麼,午餐休息時間,我看到沒有人給你一個體面的答案。我讓你jsFiddle,可能會告訴你如何完成你想要做的事情更容易。如果沒有,它應該告訴你如何更好地使用jQuery和HTML。像你正在做的那樣創建長長的HTML字符串完全擊敗了jQuery「多做多,少寫點」的目的。他們已經完成了艱苦的工作,你需要做的就是聰明地工作。

See Working jsFiddle Here

( - 阿賈克斯網址工作,因爲我沒有真正的PHP控制器打電話,但我guestimated成功的代碼,如果你把它應用到你的本地開發,它仍然應該工作一樣的)

另外,如果我更瞭解什麼期望以及發生了什麼,實際上,即使我的工作示例可能會被大約十幾行刪減。這一點,我試圖用jQuery的的「最簡單」的理解的部分,但有不同的alota的方式來完成,如「追加」 HTML和其他一些因素存在的事物。

+0

非常感謝您的SpYk3HH,這真棒!它工作的很棒...... !!!!!來自墨西哥的Saludos – maxing80 2012-04-09 21:00:04

+0

@ maxing80沒有乾草問題。我阿列格羅德闕podríaser de ayuda。 – SpYk3HH 2012-04-09 21:15:23