我试图使用jquery在textarea字段中设置一个值,代码如下:
$("textarea#ExampleMessage").attr("value", result.exampleMessage);
Run Code Online (Sandbox Code Playgroud)
问题是,一旦执行此代码,它不会改变textarea中的文本?
但是,当执行alert($("textarea#ExampleMessage").attr("value"))新设置的值时会返回?
还有另外一个关于这个问题,我试过了.但是有一个问题:textarea如果删除内容,则不会缩小.我找不到任何方法将它缩小到正确的大小 - clientHeight值返回为完整的大小,而textarea不是其内容.
该页面的代码如下:
function FitToContent(id, maxHeight)
{
var text = id && id.style ? id : document.getElementById(id);
if ( !text )
return;
var adjustedHeight = text.clientHeight;
if ( !maxHeight || maxHeight > adjustedHeight )
{
adjustedHeight = Math.max(text.scrollHeight, adjustedHeight);
if ( maxHeight )
adjustedHeight = Math.min(maxHeight, adjustedHeight);
if ( adjustedHeight > text.clientHeight )
text.style.height = adjustedHeight + "px";
}
}
window.onload = function() {
document.getElementById("ta").onkeyup = function() {
FitToContent( this, 500 ) …Run Code Online (Sandbox Code Playgroud) 我想为我的html设置一个默认值<textarea>.我从一个材料中读到,要添加默认值,你必须做类似的事情<textarea>This is default text</textarea>.我这样做但它不起作用.什么是正确的做法?
每当我开发一个包含a的新表单textarea时,我需要指定其维度时遇到以下困境:
使用CSS或使用textarea的属性cols和rows?
每种方法的优缺点是什么?
使用这些属性的语义是什么?
通常怎么做?
<textarea cols='60' rows='8'>This is my statement one.\n This is my statement2</textarea>
<textarea cols='60' rows='8'>This is my statement one.<br/> This is my statement2</textarea>
Run Code Online (Sandbox Code Playgroud)
我尝试了两个,但在渲染html文件时新行没有反映出来.我怎样才能做到这一点?
我有一个简单的文本区域,形式如下:
<textarea style="width:350px; height:80px;" cols="42" rows="5" name="sitelink">
<?php if($siteLink_val) echo $siteLink_val; ?>
</textarea>
Run Code Online (Sandbox Code Playgroud)
我在这个textarea中不断获得额外的空白区域.当我插入它时,我的光标就像在textarea的中间而不是在开头?解释是什么?
如何在<textarea>使用JavaScript中获得插入位置?
例如: This is| a text
这应该回来了7.
如何让它返回光标/选择周围的字符串?
例如:'This is', '', ' a text'.
如果突出显示"是"一词,那么它将返回'This ', 'is', ' a text'.
我无法弄清楚我的标记有什么问题,但文本区域的占位符不会出现.好像它可能被一些空格和标签覆盖.当您专注于文本区域并从光标放置的位置删除时,然后离开文本区域,然后会出现正确的占位符.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
</head>
<body>
<form action="message.php" method="post" id="message_form">
<fieldset>
<input type="email" name="email" id="email" title="Email address"
maxlength="40"
placeholder="Email Address"
autocomplete="off" required />
<br />
<input type="text"
name="subject"
id="subject" title="Subject"
maxlength="60" placeholder="Subject" autocomplete="off" required />
<br />
<textarea name="message"
id="message"
title="Message"
cols="30"
rows="5"
maxlength="100"
placeholder="Message" required>
</textarea>
<br />
<input type="submit" value="Send" id="submit"/>
</fieldset>
</form>
</body>
<script>
$(document).ready(function() {
$('#message_form').html5form({
allBrowsers : true,
responseDiv : '#response',
messages: 'en',
messages: 'es',
method : 'GET',
colorOn …Run Code Online (Sandbox Code Playgroud) disabled文本框或文本区域的属性的正确值是什么?
我见过以下用过:
<input type="text" disabled />
<input type="text" disabled="disabled" />
<input type="text" disabled="true" />
Run Code Online (Sandbox Code Playgroud) 为什么有一个元素<textarea>而不是<input type="textarea">?