我有一个功能,可以回显网页的常用代码。如果我这样做的代码:
echo '<tr>';
CSCell("{$row['home_team']}/{$row['home_team']}",'home_home',$row, 1);
echo '</tr><tr>';
CSCell("{$row['home_team']}/Draw",'home_draw',$row, 1);
echo '</tr><tr>';
它没有问题。如果我这样做:
echo '<tr>' . CSCell("{$row['home_team']}/{$row['home_team']}",'home_home',$row, 1) . '</tr>';
echo '<tr>' . CSCell("{$row['home_team']}/Draw",'home_draw',$row, 1) . '</tr>';
它为每行代码输出一个额外的空行。据推测它最初是回声&lt; tr&gt;然后函数输出数据然后它返回null
(因为没有指定返回)然后它再次开始回声(没有重新调用函数&amp;打印&lt; tr&gt; 空字符串&lt; / TR&GT;)
如何阻止它重新回显tr
HTML?该函数仅包含td
回波数据?
我现在懒得让它返回,因为它需要回显的地方引用了其他部分。如何修改函数以便它可以用于回显和返回?
答案 0 :(得分:1)
由于您已经依赖其他代码中的输出,只需在函数中添加第五个参数即可将其告诉data-src
或// Register for Activities section of the form.
document.querySelector(".activities").addEventListener("change", function(){
var main = document.getElementById("all");
var framework = document.getElementById("framework");
var libs = document.getElementById("libs");
var express = document.getElementById("express");
var node = document.getElementById("node");
var build = document.getElementById("build");
var npm = document.getElementById("npm");
var frameworkLbl = document.getElementById("frameworkLabel");
var libsLbl = document.getElementById("libsLabel");
var expressLbl = document.getElementById("expressLabel");
var nodeLbl = document.getElementById("nodeLabel");
// If the user selects a workshop, don't allow selection of a workshop at the same date and time -- you should disable the checkbox and visually indicate that the workshop in the competing time slot isn't available.
if(framework.checked == true) {
express.disabled = true;
expressLbl.style.color = "grey";
}
if(express.checked == true) {
framework.disabled= true;
frameworkLbl.style.color = "grey";
}
if(libs.checked == true) {
node.disabled = true;
nodeLbl.style.color = "grey";
}
if(node.checked == true) {
libs.disabled = true;
libsLbl.style.color = "grey";
}
// When a user unchecks an activity, make sure that competing activities (if there are any) are no longer disabled.
if(framework.checked == false) {
express.disabled = false;
expressLbl.style.color = "black";
}
if(express.checked == false) {
framework.disabled = false;
frameworkLbl.style.color = "black";
}
if(libs.checked == false) {
node.disabled = false;
nodeLbl.style.color = "black";
}
if(node.checked == false) {
libs.disabled = false;
libsLbl.style.color = "black";
}
});
:
echo
然后使用return
调用它:
function CSCell($a, $b, $c, $d, $return=false) {
// build $output
if($return) { return $output; }
echo $output;
}
如果无法修改该函数,则构建一个包装器并缓冲输出并返回。我不知道函数是什么样的,所以你需要检查参数或依赖$return = true
函数来验证它们:
echo '<tr>' . CSCell("{$row['home_team']}/Draw", 'home_draw', $row, 1, true) . '</tr>';
然后调用包装函数:
CSCell()