textarea 换行问题。。。 在textarea中一按回车键就会换行,但是我不希望出现换行,而是让内容直接在一行里显示。我取出了textarea的innerhtml发现里面根本没有换行符号,但在textarea中就是换行显示。求解? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那 lz 的意思是希望在 textarea 中屏蔽回车键?另,在 textarea 中的换行符是“\r\n”,是不可见字符! 要实现这样的功能,就不用textarea了直接用个input type=text 然后设置一个高度就ok了 屏蔽回车键L@_@K<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title> new document </title> <meta name="generator" content="editplus" /> <meta name="author" content="[email protected]" /> <meta name="keywords" content="" /> <meta name="description" content="" /></head><body><textarea id="myTextArea" rows="20" cols="70"></textarea><input type="button" value="Show" id="showBtn" /><script type="text/javascript"><!-- var EnterKeyCode = 13; var myTextArea = document.getElementById("myTextArea"); myTextArea.value = "hehe\r\nhaha" myTextArea.onkeydown = function() { // 屏蔽回车键! if (event.keyCode == EnterKeyCode) event.returnValue = false; }; var showBtn = document.getElementById("showBtn"); showBtn.onclick = function() { alert(myTextArea.value.indexOf("\r\n")); };//--></script></body></html>Web 开发常用手册DHTML 参考手册http://download.csdn.net/source/308913JScript 语言参考http://download.csdn.net/source/308916CCS 样式表中文手册http://download.csdn.net/source/304124 可以L@_@K<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title> new document </title> <meta name="generator" content="editplus" /> <meta name="author" content="[email protected]" /> <meta name="keywords" content="" /> <meta name="description" content="" /></head><body><textarea id="myTextArea" rows="20" cols="70"></textarea><input type="button" value="消除换行" id="showBtn" /><script type="text/javascript"><!-- var myTextArea = document.getElementById("myTextArea"); myTextArea.value = "hehe\r\nhaha" var showBtn = document.getElementById("showBtn"); showBtn.onclick = function() { myTextArea.value = myTextArea.value.replace("\r\n", ""); };//--></script></body></html> 但是我用textarea的onkeypress事件怎么不行呢? 哎,粗心了。特别感谢yixianggao的回答。 我怎么看不见yixianggao的回答呢?还是显示需要先登录.... 怎么把这个时间格式转为纯数字的时间轴形式呢 找图片数量问题 php用file怎样可以上传多个文件啊 JS语句调用各大搜索引擎搜索中文乱码问题 求一个替换文字函数 新开窗口如何读取父窗口或返回值给父窗口 请教下列代码什么意思,我要怎么改? 怎样使两个下拉菜单相互关联?数据是从数据库中读取的!! js实现全选功能出错了 js问题 怎么理解函数实例 Ext toolbar
直接用个input type=text 然后设置一个高度就ok了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="[email protected]" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>
<body>
<textarea id="myTextArea" rows="20" cols="70"></textarea>
<input type="button" value="Show" id="showBtn" />
<script type="text/javascript">
<!--
var EnterKeyCode = 13;
var myTextArea = document.getElementById("myTextArea");
myTextArea.value = "hehe\r\nhaha"
myTextArea.onkeydown = function() {
// 屏蔽回车键!
if (event.keyCode == EnterKeyCode)
event.returnValue = false;
};
var showBtn = document.getElementById("showBtn");
showBtn.onclick = function() {
alert(myTextArea.value.indexOf("\r\n"));
};
//-->
</script>
</body>
</html>
Web 开发常用手册DHTML 参考手册
http://download.csdn.net/source/308913JScript 语言参考
http://download.csdn.net/source/308916CCS 样式表中文手册
http://download.csdn.net/source/304124
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="[email protected]" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>
<body>
<textarea id="myTextArea" rows="20" cols="70"></textarea>
<input type="button" value="消除换行" id="showBtn" />
<script type="text/javascript">
<!--
var myTextArea = document.getElementById("myTextArea");
myTextArea.value = "hehe\r\nhaha"
var showBtn = document.getElementById("showBtn");
showBtn.onclick = function() {
myTextArea.value = myTextArea.value.replace("\r\n", "");
};
//-->
</script>
</body>
</html>
但是我用textarea的onkeypress事件怎么不行呢?