Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 选择以字符开头的所有表格单元格_Php_Jquery_Html_Jquery Selectors - Fatal编程技术网

Php 选择以字符开头的所有表格单元格

Php 选择以字符开头的所有表格单元格,php,jquery,html,jquery-selectors,Php,Jquery,Html,Jquery Selectors,我正在接收外部表格数据,并将其转储到HTML表格中。他们的系统以破折号开始每个表格标题行,例如“-Lorem ipsum”。我写了下面的代码片段来鼓励标题,但它不起作用——我一定错过了什么 $(".csvTable td").each(function () { var cellValue = $(this).text(); if (cellValue.indexOf("-")) $(this).wrapInner( "<strong>&

我正在接收外部表格数据,并将其转储到HTML表格中。他们的系统以破折号开始每个表格标题行,例如“-Lorem ipsum”。我写了下面的代码片段来鼓励标题,但它不起作用——我一定错过了什么

$(".csvTable td").each(function () 
{    
    var cellValue = $(this).text();

    if (cellValue.indexOf("-")) 
        $(this).wrapInner( "<strong></strong>");
});
$(“.csvTable td”)。每个(函数()
{    
var cellValue=$(this.text();
if(cellValue.indexOf(“-”))
$(this.wrapInner(“”);
});

(它是用PHP呈现的,所以如果您认为在那里处理它更好,那么请共享!)

在JavaScript中,
indexOf
如果找到,则返回一个索引,如果没有,则返回-1

如果您想知道它是否以该字符开头,可以说If value.indexOf(“-”==0

是的,我认为你应该使用PHP。它看起来是这样的:

if (strpos($val, "-") === 0) {
   $val = "<strong>$val</strong>";
}
if(strpos($val,“-”)==0){
$val=“$val”;
}

如注释中所述,请尝试以下操作:

cellValue.indexOf("-") == 0

请尝试此单元格值。indexOf(“-”)==0请更正!哈,我认为0是隐含的。作为正确的答案提交,我会接受你的答案。非常感谢!将给出一个答案,这样你就可以结束这个问题了..只是一个完全相关的.indexOf提示:而不是
strOrArray.indexOf(“-”)=-1
,它通常用于检查字符串/数组中是否有字符串,您还可以执行
~strOrArray.indexOf(“-”)
~
将执行按位NOT,因此-1变为0,这被解释为
false
,而所有其他值将变为非0,因此它们被解释为
true
@felixthehat no problem.)