函数中的PHP echo$变量也写入=“&引用;到html
下面的PHP还将函数中的PHP echo$变量也写入=“&引用;到html,php,Php,下面的PHP还将=“”写入html代码,而不是像预期的那样只写入变量值。 如何摆脱HTML代码中的=”废话 PHP: while($row=$result->fetch_assoc()){ $select=“”; 未设置($id,$name); $id=$row['customerID']; $name=$row['name']; if($\u会话['customerID']==$id){ $select='selected'; } 回显“.$name.”; } 最后一行带有“selected
=“”
写入html代码,而不是像预期的那样只写入变量值。
如何摆脱HTML代码中的=”
废话
PHP:
while($row=$result->fetch_assoc()){
$select=“”;
未设置($id,$name);
$id=$row['customerID'];
$name=$row['name'];
if($\u会话['customerID']==$id){
$select='selected';
}
回显“.$name.”;
}
最后一行带有“selected”的HTML结果:
<form><select onchange="showUser(this.value)" name="id">
<option value="">Select Customer</option>
<option value="0">Customer2</option>
<option selected="" value="1">Customer1</option></select></form>
选择客户
顾客2
顾客1
预期结果:
<form><select onchange="showUser(this.value)" name="id">
<option value="">Select Customer</option>
<option value="0">Customer2</option>
<option selected value="1">Customer1</option></select></form>
选择客户
顾客2
顾客1
下面的PHP还将=“”
写入html代码,而不是像预期的那样只写入变量值
无论何时如果
条件失败,您都会在值
属性之后看到此=''
。您的代码应该如下所示:
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['customerID'];
$name = $row['name'];
$option = "<option value='{$id}'";
if ($_SESSION['customerID'] == $id){
$option .= " selected";
}
$option .= ">{$name}</option>";
echo $option;
}
while($row=$result->fetch_assoc()){
未设置($id,$name);
$id=$row['customerID'];
$name=$row['name'];
$option=“{$name}”;
echo$期权;
}
下面的PHP还将=“”
写入html代码,而不是像预期的那样只写入变量值
无论何时如果
条件失败,您都会在值
属性之后看到此=''
。您的代码应该如下所示:
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['customerID'];
$name = $row['name'];
$option = "<option value='{$id}'";
if ($_SESSION['customerID'] == $id){
$option .= " selected";
}
$option .= ">{$name}</option>";
echo $option;
}
while($row=$result->fetch_assoc()){
未设置($id,$name);
$id=$row['customerID'];
$name=$row['name'];
$option=“{$name}”;
echo$期权;
}
您是从view source还是inspect element看到这一点的?您是否使用了“view source”或chrome开发者工具/firebug?因为开发人员工具可能与源代码不同。确实要签入“查看源代码”。实际来源是好的。谢谢。你是从view source还是inspect element看到的?你使用“view source”还是chrome开发者工具/firebug?因为开发人员工具可能与源代码不同。确实要签入“查看源代码”。实际来源是好的。谢谢。我可以知道这次否决的原因吗?我可以知道这次否决的原因吗?