【发布时间】:2016-07-21 11:45:46
【问题描述】:
我想了解为什么我的<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>
【问题讨论】: