我想了解为什么我的 <textarea>
当我登陆页面时,框包含空白。我已经放置了一个 if(empty ($_POST['textarea'])
在提交前检查它是否有文本。我无法获得 if(empty ($_POST['textarea'])
开始工作,直到我注意到 <textarea>
中的空格.一旦我删除了空格 if(empty ($_POST['textarea'])
条件有效。
在我点击进入文本区域之前,已经有空白 - 为什么会发生这种情况,我该如何预防?
这是我的代码。
文本区域:
echo '<div id="container">
<textarea style=width:500px; font-size:14px; height:60px;font-weight:bold;
name= "name" id="name" >
</textarea>
</div>
我正在使用 jQuery 通过 AJAX 发送:
<script src="js/jquery.js"></script>
<div id="showResult"></div>
<script>
$(document).ready (function()
{
// Focus on textarea
$('#name').focus();
// '#msg' id of button
$('#msg').on('click', function() {
//to disable button after click
this.disabled = true;
// '#name' is the id value of textarea name
var info = $('#name').val();
$.ajax ({
method: "POST",
url: "actions/message_action.php",
//pass my variables to ajax - jq here in data name:
data: {name: info, recptid: '<?php echo $_GET["id"]; ?>'
},
//feed the success my data to return results
success: function(data){
$('#data').append(status);
$("#showResult").text(data);
//window.alert(data);
$('#data').val('Sent');
}
});
return false;
});
});
</script>
最佳答案
空白是由您格式化 HTML 的方式生成的:
<textarea style=width:500px; font-size:14px; height:60px;font-weight:bold;
name= "name" id="name" >
</textarea>
这会在文本区域中创建一个空格和换行符。将您的 HTML 更改为:
<textarea style=width:500px; font-size:14px; height:60px;font-weight:bold;
name= "name" id="name" ></textarea>
编辑
我可以看到您已将文本区域命名为 name
,这向我表明您可能想要使用 <input type="text">
相反,因为文本区域用于多行文本。
关于php - 从 Text-Area 中删除空白,为什么它在那里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38503411/