我在一个页面上有几个输入框,我希望文本从左上角开始。目前,我在下面使用的,它是向左对齐的,但在框的中间。我试过垂直对齐和其他方法,但都不成功。我不想用填充,因为文本需要换行它只会让它跳出框的顶部:
<input style="height:200px;width:800px;font-family:Arial;border:1px solid #a6a6a6;
background-color:#fff9eb;resize:none" wrap="hard"
id="submitsummary" name="submitsummary"
placeholder="1000 character limit..."
maxlength="1000" size="1000" type="text"/>
编辑-所以根据建议,我把它改回textarea,现在我的HTML中有了textarea框(简化为在表单中显示它):
<form id="submitform" name="submitform" action="submit.php" onsubmit="return validateSubmitForm()" method="post">
<textarea style="height:60px;width:600px;font-family:Arial;border:1px solid #a6a6a6;
background-color:#fff9eb;resize:none" wrap="hard" size="200"
placeholder="200 character limit..." maxlength="200"
id="submitsummary" name="submitsumary" type="text"></textarea>
<p id="submitsummaryfail"></p>
<input type="submit" value="Submit" class="btn">
</form>
我要做的是一个验证函数:
<script>
function validateSubmitForm()
{
var submitsummary=$('#submitsummary').val();
// check that summary isn't blank
if (submitsummary==null || submitsummary=="")
{
$('#submitsummaryfail').html("Summary cannot be blank");
return false;
}
else
{
$('#submitsummaryfail').html("");
return true;
}
}
</script>
根据您的评论,您可以使用<textarea>
,然后用jquery .val()
获取值:
var text = $("#submitsummary").val();
https://stackoverflow.com/a/13321580/802791