简体   繁体   English

asp.net中的内容前有空白的Textarea

[英]Textarea having white space before content in asp.net

在此处输入图片说明

In IE10, textarea showing white space before content after saving in asp.net,then how to remove that white space using jquery or javascript or css it is working fine in IE9 and IE8 but not in IE10 and text should be display in place of white space like second image: 在IE10中,将文本区域保存在asp.net中后,textarea在内容之前显示空白,然后如何使用jquery或javascript或css删除该空白,在IE9和IE8中它可以正常工作,但在IE10中则不能,并且文本应该显示为白色像第二张图片一样的空间:

图片

You can use trim() function 您可以使用trim()函数

var str = "       Hello World!        ";
alert(str.trim());

The trim() method removes whitespace from both sides of a string. trim()方法从字符串的两侧删除空格。 Note: The trim() method does not change the original string. 注意:trim()方法不会更改原始字符串。

For browsers that do not support the trim() method, you can remove whitespaces from both sides of a string with a regular expression: 对于不支持trim()方法的浏览器,可以使用正则表达式从字符串的两侧删除空格:

function myTrim(x) {
    return x.replace(/^\s+|\s+$/gm,'');
}

function myFunction() {
    var str = myTrim("        Hello World!        ");
    alert(str);
}

You can solve with using below approaches: 您可以使用以下方法解决:

using jQuery : 使用jQuery:

$('#textareId').html(vdt_demo_table_string.replace(/ /g, ' '));

Using CSS: 使用CSS:

textarea{
white-space:pre;
}

OR 要么

textarea{
white-space:pre-wrap;
}

Hope it will helps you. 希望对您有帮助。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM