在输入类型文本中,我只得到一个字符串。例如,如果数据库名称字段中有“abc xyz”。所以它只显示 abc 而不是全名,所有字段都会发生这种情况。请同时检查我的代码。
while($row = mysqli_fetch_array($result))
{
//print_r($row['name']);
echo "<tr>";
echo "<td> ". $row['id'] . "</td>";
echo "<td> <input type=text placeholder = name onchange= nameValidation(this) value = ".$row["name"]." disabled> </td>";
echo "<td> <input type='email' placeholder = 'email' value = ". $row['email'] ." onchange= nameValidation(this) disabled> </td>";
echo '<td> <input type="button" value="edit" onclick="edit(this)">
<input type="button" value="update" onclick="update(this)" style="display:none;">
<input type="button" value="Delete" onclick="delete1(this)" style="display:none;">
</td>';
echo "</tr>";
}
echo "</table>";
最佳答案
HTML 规范 says :
Attributes are placed inside the start tag, and consist of a name and a value, separated by an "=" character. The attribute value can remain unquoted if it doesn't contain ASCII whitespace or any of " ' ` = < or >. Otherwise, it has to be quoted using either single or double quotes. The value, along with the "=" character, can be omitted altogether if the value is the empty string.
在本例中,文本“abc xyz”确实包含空格,因此必须用引号引起来。但它不在你的代码中。 PHP 完成解析后,您的 input
标记将是:
<input type=text placeholder = name onchange= nameValidation(this) value = abc xyz disabled>
其中,“abc”将被解释为值,“xyz”将被解释为另一个未知属性。
要纠正此问题,您需要使用 \"
引用该值,如下所示:
echo "<td> <input type=text placeholder=name onchange=nameValidation(this) value=\"" . $row["name"] . "\" disabled> </td>";
或者您可以切换到单引号:
echo '<td>';
echo '<input type="text" placeholder="Enter your name" onchange="nameValidation(this)" value="' . $row['name'] . '" disabled>';
echo '</td>';
关于php - 重新加载 php 脚本时,输入文本字段中空格字符后的文本被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54799469/