2012-06-14 13 views
7

see fiddle se il paziente ha già assegnato un time slot, quindi creare un colore giallo utilizzando jquery (lato client). nel mio caso, se alloco la fascia oraria per la prima volta, il colore è verde e allo stesso tempo quando si assegna lo slot successivo allo allo slot precedente è grigio. devo farlo diventare giallo per quello devo trovare tag span nella tabella e controllare che contenga testo o meno se contiene testo quindi renderlo giallo.Ma sono nuovo in jquery.i cercare il lotto ma non ottenere. come posso farlo.come chk se il tag span contiene testo o meno

// Questo è il codice scatto del tasto

$("#<%=btnSelect.ClientID%>").click(function()   { 


       var cells = $('#tableAppointment tbody tr td:nth-child(3)'); 


       var i = 0; 
       var topcell = false; 

       cells.each(function() 
       { 
        var $cell = $(this); 

        if ($cell.hasClass('csstdhighlight')) 
        { 
         if (i == 0) 
         { 
          $cell.find('span').text(jQuery('#<%=txtPatientName.ClientID%>').val()); 
          topcell = $cell; 
         } 
         else 
         { 
          $cell.remove(); 

         } 
         i++; 
        } 
       }); 
       if (topcell && i > 1) topcell.attr('rowspan', i); 
       $("#tableAppointment tr").each(function() 
       { 

        $('td', this).each(function() 
        { 
         var value = $(this).find("span").val(); 

         if (!value)//i m chking like this 
         { 

         } 
         else 
         { //make it yellow      
         } 
        }) 

       }) 

       return false; 
      }); 
     }); 
+0

'$ ('# tableAppointment tbody tr td: nth-child (3)')' restituisce un solo elemento e l'utilizzo di ogni è ridondante . – undefined

+0

console.log non è definito –

+0

no, console.log() non è indefinito. – undefined

risposta

2

Invece di questo

var value = $(this).find("span").val(); 

scrittura

var value = $(this).find("span").text(); 

e se si desidera controllare l'HTML all'interno lasso quindi utilizzare

var value = $(this).find("span").html(); 

UPDATE: -

<html><head> 
<style>.yell{background:#CCFF00;}.csstd 
{ 
background-color: #ccffcc; 
} 
table{ 
background-color: #cccccc; 

}</style><script src="jquery.js"></script> 
<script>var is=false; 
$(function(){ 

$(document).mouseup(function(){is=false;}); 
$(".csstablelisttd").mousedown(function(e){sen=$(this); 
$(".csstd").removeClass("csstd"); 
    $(this).children(":not(:first)").addClass("csstd"); 
    xco=e.clientX; 
    yco=e.clientY; 
    is=true; 
    return false; 
}); 
document.onmousemove=function(){return false;}; 
$(".csstablelisttd").mouseenter(function(){ 
if(is){ 
    $(this).children(":not(:first)").addClass("csstd"); 
if($(".csstd").length>=6){is=false;} 
} 
}); 
$("#update").click(function(){ 
if($("#names").val()) 
{ 
$(".csstd").next().hide(); 

$(".csstd:first").next().show().attr("rowspan",$(".csstd").length/2).children().html($("#names").val()); 
$(".csstd").removeClass("csstd").addClass("yell"); 
} 
}); 
});</script></head><body> 
<table id="tableAppointment" cellspacing="1" width="50%" border="1" align="center"> 
<thead> 
<tr class="csstablelisttd"> 
<td bgcolor="#ffffff"> 
</td> 
<td > 
</td> 
<td class="csstablelisttd patientName"> 
<b>Patient Name</b> 
</td> 
</tr> 
</thead> 
<tbody> 
<tr class="csstablelisttd"> 
<td valign="top" width="70px"> 
8:00AM 
</td> 
<td > 
0 
</td> 
<td > 
<span></span> 
</td> 
</tr> 
<tr class="csstablelisttd"> 
<td > 
</td> 
<td > 
15 
</td> 
<td > 
<span></span> 
</td> 
</tr> 
<tr class="csstablelisttd"> 
<td > 
</td> 
<td > 
30 
</td> 
<td > 
<span></span> 
</td> 
</tr> 
<tr class="csstablelisttd"> 
<td > 
</td> 
<td > 
45 
</td> 
<td > 
<span></span> 
</td> 
</tr> 
<tr class="csstablelisttd"> 
<td valign="top" width="90px"> 
9:00AM 
</td> 
<td > 
0 
</td> 
<td > 
<span></span> 
</td> 
</tr> 
<tr class="csstablelisttd"> 
<td > 
</td> 
<td > 
15 
</td> 
<td > 
<span></span> 
</td> 
</tr> 
<tr class="csstablelisttd"> 
<td > 
</td> 
<td > 
30 
</td> 
<td > 
<span></span> 
</td> 
</tr> 
<tr class="csstablelisttd"> 
<td > 
</td> 
<td > 
45 
</td> 
<td > 
<span></span> 
</td> 
</tr> 
</tbody> 
</table> 
<input type="text" id="names" /> 
<input type="button" id="update" value="update" /> </body></html> 
+0

+1 grazie ....... ma Come scorrere la tabella se lo span contiene testo, quindi fissare l'appuntamento con il colore giallo. –

+0

ru c'è qualcuno nei guai –

+0

ru in javascript room –

3

Usa $(this).find("span").text() invece. Controlla se la stringa restituita è vuota.

+0

+1 grazie .... ... ma Come scorrere la tabella se lo span contiene del testo, quindi rendere quell'appuntamento con il colore giallo. –

3
if($('span').text().length == 0){ 
    console.log('No Text'); 
} 
else{ 
    console.log('Has Text'); 
} 

Demo: http://jsfiddle.net/hj4Bt/1/

+1

funziona anche senza lunghezza anche –

+0

+1 grazie..ma. Come eseguire un'iterazione nella tabella se lo span contiene del testo, quindi rendere quell'appuntamento con il colore giallo. –

+0

@Nikhil Controlla la demo – Dipak

1

E 'questo che vuoi?

See demo: http://jsfiddle.net/FDEep/3/

$('input').click(function(){ 
    // All <span> inside <td> 
    $('td span').each(function(index){ 
     // Check if 'span' is empty 
     if($(this).text().length !== 0){ 
      // Change the bg color of the 'span' not empty 
      $(this).parent().css('background-color', 'yellow'); 
      // When a span with some value is found, alert the index of the row 
      alert($(this).closest('tr')[0].rowIndex); 
     } 
    }); 
}); 

Adattare alla vostra volontà

+0

hi void ......... –

Problemi correlati