2012-06-14 10 views
7

see fiddle यदि रोगी के पास पहले से आवंटित समय स्लॉट है तो jquery (क्लाइंट साइड) का उपयोग करके रंग पीला रंग दें। मेरी पहेली में अगर मैं पहली बार समय स्लॉट आवंटित करता हूं तो रंग हरा होता है और साथ ही अगली बार स्लॉट आवंटित होने पर पिछली बार स्लॉट ग्रे होता है। मुझे इसे पीला बनाना है। इसके लिए मुझे टेबल में स्पैन टैग ढूंढना है और चेकर में टेक्स्ट शामिल है या नहीं यदि पाठ है तो इसे पीला बनाओ। लेकिन मैं jquery.i में बहुत नया हूं लेकिन खोज नहीं रहा हूं। मैं यह कैसे कर सकता हूं।स्पैन टैग में टेक्स्ट कैसे होता है या नहीं

// इस बटन पर क्लिक कोड

$("#<%=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: n वें वाले बच्चे (3)')' केवल एक ही तत्व और का उपयोग कर रिटर्न प्रत्येक अनावश्यक है । – undefined

+0

console.log अपरिभाषित –

+0

नहीं है, console.log() अपरिभाषित नहीं है। – undefined

उत्तर

2

के बजाय इस

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

लिखने

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

है और आप अवधि के अंदर एचटीएमएल जाँच करना चाहते हैं तो

का उपयोग
var value = $(this).find("span").html(); 

अद्यतन: -

<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 धन्यवाद ....... लेकिन यदि पाठ में टेक्स्ट होता है तो टेबल के माध्यम से पुनरावृत्ति कैसे करें, फिर उस पीले रंग के साथ उस नियुक्ति को बनाएं। –

+0

ru वहाँ कोई समस्या है –

+0

जावास्क्रिप्ट कक्ष में –

3

उपयोग $(this).find("span").text() बजाय। जांचें कि लौटाई गई स्ट्रिंग खाली है या नहीं।

+0

+1 धन्यवाद .... ... लेकिन यदि पाठ में टेक्स्ट होता है तो टेबल के माध्यम से पुनरावृत्ति कैसे करें, फिर उस पीले रंग के साथ उस नियुक्ति को बनाएं। –

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

डेमो: http://jsfiddle.net/hj4Bt/1/

+1

यह बिना लंबाई के काम करता है –

+0

+1 धन्यवाद..लेकिन यदि पाठ में टेक्स्ट होता है तो टेबल के माध्यम से पुनरावृत्ति कैसे करें, फिर उस पीले रंग के साथ उस नियुक्ति को बनाएं। –

+0

@ निखिल डेमो की जांच करें – Dipak

1

कि तुम क्या चाहते है? डेमो

देखें: 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); 
     } 
    }); 
}); 

अपनी इच्छा पर अनुकूल

+0

हाय शून्य ......... मदद चाहिए –

संबंधित मुद्दे