有没有办法检查表格单元格是否具有特定内容并在该单元格的左上角用符号“◤”标记该单元格?谢谢
			
			1048 次
		
5 回答
            2        
        
		
使用这个查找和替换功能:
  function ReplaceCellContent(find, replace)
    {
        $("#table tr td:contains('" + find + "')").html(replace);
    }
    于 2013-03-11T14:03:32.083   回答
    
    
            2        
        
		
您可能不想替换内容,只需用“◤”标记感兴趣的单元格。
你可以使用 CSS:before来做到这一点
<table>
<tr>
    <td>lorem</td>
    <td>lorem</td>
</tr>
<tr>
    <td>ipsum</td>
    <td>lorem</td>
</tr>
</table>
JS:
$("td:contains('ipsum')").addClass('found');
工作示例:http: //jsfiddle.net/3NWQD/1/
于 2013-03-11T14:15:24.127   回答
    
    
            1        
        
		
示例 JSFiddle 答案:http: //jsfiddle.net/ATV4G/1/
Javascript:
    function markCell(containingText, replaceWith) { //making our function
        $("td:contains('"+containingText+"')").prepend("<span class='abs'>"+replaceWith+"        </span>");
    }
    markCell("first", "◤"); //calling the function
CSS:
    .abs {
            position: absolute;
    }
HTML:
    <table>
            <tr>
                <td>first</td>
                <td>second</td>
            </tr>
    </table>
这些是最低要求。如果想美化输出,可以进一步写CSS来实现需求。(请查看 JSFiddle 示例)
希望这可以帮助你:)
于 2013-03-11T14:57:11.837   回答
    
    
            0        
        
		
试试这个
HTML
<table border="1" id="table">
    <tr><th>No</th><th>Player Name</th></tr>
    <tr><td>1</td><td>Sachin</td></tr>
    <tr><td>2</td><td>Dhoni</td></tr>
    <tr><td>3</td><td>Raina</td></tr>
    <tr><td>4</td><td>Yuvi</td></tr>
    <tr><td>5</td><td>Sachin</td></tr>
  </table>
jQuery
function MarkCell(PlayerName)
{
    $("td").each(function(){ 
        //alert($(this).text());
        if($(this).text() == PlayerName)
        {
            $(this).html('◤' + PlayerName);
        }
    });
}
MarkCell('Sachin');
在这里生活小提琴
于 2013-03-11T14:33:52.440   回答
    
    
            -1        
        
		
这是一个PHP解决方案。
假设您连接了一个 MySQL 数据库,并且该表包含“state_or_province”、“city”和“country”列。如果你想用“GA”的州或省值标记所有单元格,你可以使用这样的东西:
echo "<table>
        <tr>
            <th>State</th>
            <th>City</th>
            <th>Country</th>
        </tr>";
while($row = mysql_fetch_array($myresults)){
    echo "<tr>";
            if($row["state_or_province"] == "GA"){
                echo "<td class = 'red'>".$row["state_or_province"]."</td>";
            }
            else{
                echo "<td>".$row["state_or_province"]."</td>";
            }
            echo "<td>".$row["city"]."</td>
                  <td>".$row["country"]."</td>
                  </tr>";
}
echo "</table>";
在您的 CSS 样式部分中,包括以下内容
.red{
    background-color: red;
}
在此示例中,在我们呈现的表格的“状态”列下具有值“GA”的所有单元格都将显示在红色单元格中。如果您想让“◤”符号出现在左上角,只需编辑上面的 CSS
更新
改变
        if($row["state_or_province"] == "GA"){
            echo "<td class = 'red'>".$row["state_or_province"]."</td>";
        }
到
        if($row["state_or_province"] == "GA"){
            echo "<td class = 'red'>◤".$row["state_or_province"]."</td>";
        }
你会看到文本框内的三角形
于 2013-03-11T14:24:52.280   回答