我有这样的文字字符串:
Jenny Lewis . Pretty Bird Sergio Mendes & Brasil 66 . For What it’s
Worth Petra Magoni feat. Jean-Jacques Milteau & Manu Galvin . Fever
Emiliana Torrini . Me and Amini Cowboy Junkies . Run for your Life Mira
Billotte . As I Went out in the Morning Nitin Sawhney feat. Tina Grace
. October Daze Isobel Campbell . Saturday’s Gone Barbara . Mes
Hommes...
我想在我的字符串中使用换行符作为我表的参数。我想要这样的东西:
Jenny Lewis . Pretty Bird Sergio Mendes & Brasil 66 .
For What it’s Worth Petra Magoni feat. Jean-Jacques Milteau & Manu Galvin .
Fever Emiliana Torrini . Me and Amini Cowboy Junkies .
Run for your Life Mira Billotte . As I Went out in the Morning Nitin Sawhney feat.
Tina Grace . October Daze Isobel Campbell .
Saturday’s Gone Barbara . Mes Hommes...
它可以是(\ n)或任何其他角色。在每行的末尾有一个换行符。 有人有想法吗?
答案 0 :(得分:2)
您的问题的表述不正确。 ("...i want to use the line break characte..."
比你说"...It can be a (\n) or any other character. ..."
)
您可以使用代码</br>
Jenny Lewis . Pretty Bird Sergio Mendes & Brasil 66 .</br> For What it’s
Worth Petra Magoni feat. Jean-Jacques Milteau & Manu Galvin .</br> Fever
Emiliana Torrini . Me and Amini Cowboy Junkies .</br> Run for your Life Mira
Billotte . As I Went out in the Morning Nitin Sawhney feat.</br> Tina Grace
. October Daze Isobel Campbell .</br> Saturday’s Gone Barbara . Mes
Hommes...
&#13;
答案 1 :(得分:0)
请再解释一下你的问题。该字符串是否放在一列中?如果是这样,那么为什么不将列设为特定宽度E.g:
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table>
<col width="330">
<col width="80">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>Jenny Lewis . Pretty Bird Sergio Mendes & Brasil 66 . For What it’s
Worth Petra Magoni feat. Jean-Jacques Milteau & Manu Galvin . Fever
Emiliana Torrini . Me and Amini Cowboy Junkies . Run for your Life Mira
Billotte . As I Went out in the Morning Nitin Sawhney feat. Tina Grace
. October Daze Isobel Campbell . Saturday’s Gone Barbara . Mes
Hommes...</td>
<td>This is under column 2</td>
</tr>
<tr>
<td>This is another long string. This is another long string. This is another long string. This is another long string. This is another long string. This is another long string. This is another long string. This is another long string. This is another long string. </td>
<td>Again this is under column 2... also a long string:Again this is under column 2... also a long string: Again this is under column 2... also a long string: Again this is under column 2... also a long string: </td>
</tr>
</table>
<p>The col width attribute is not supported in HTML5.</p>
</body>
</html>
或者您希望其中每一个都在单独的列/行
中答案 2 :(得分:0)
我不知道我是否应该这样做。
{if $category-> == 90 || $category->id == 95 || $category-> == 96}
{/if}
这是我的完整代码。我想要一个为每一行创建单元格的表。
答案 3 :(得分:0)
独立代码
var details = {};
details.text_tracks = "Jenny Lewis . Pretty Bird Sergio Mendes & Brasil 66 .\n For What it’s Worth Petra Magoni feat. Jean-Jacques Milteau & Manu Galvin .\n Fever Emiliana Torrini . Me and Amini Cowboy Junkies .\n Run for your Life Mira Billotte . As I Went out in the Morning Nitin Sawhney feat.\n Tina Grace . October Daze Isobel Campbell .\n Saturday’s Gone Barbara . Mes Hommes...\n";
details.text_tracks = details.text_tracks.replace(/(?:\r\n|\r|\n)/g, '<br />');
document.getElementById("my-text").innerHTML = details.text_tracks;
<div id="my-text">
</div>
代码中的修改
您应该将{n替换为<br>
使用以下代码
var details.text_tracks = "Jenny Lewis . Pretty Bird Sergio Mendes &
Brasil 66 .\n For What it’s Worth Petra Magoni feat. Jean-Jacques
Milteau & Manu Galvin .\n Fever Emiliana Torrini . Me and Amini Cowboy
Junkies .\n Run for your Life Mira Billotte . As I Went out in the
Morning Nitin Sawhney feat.\n Tina Grace . October Daze Isobel Campbell
.\n Saturday’s Gone Barbara . Mes Hommes...\n"
details.text_tracks = details.text_tracks .replace(/(?:\r\n|\r|\n)/g, '<br />');
您也可以在发送客户端之前在服务器端代码中执行此操作。
答案 4 :(得分:0)
我不确定您的要求是什么,但据我了解,您希望将文本字符串放在一个文本区域或文本框中。
您可以使用HTML通过以下代码构建文本区域
<th colspan="3" rowspan="9" id="textarea">
<textarea id = "textInput" rows = "13" cols = "100">
</textarea>
</th>
您可以定义colspan,rowspan,id,rows和cols。 在javascript中你可以使用,
textarea = document.getElementById('textInput');
textarea.value = 'Jenny Lewis . Pretty Bird Sergio Mendes & Brasil 66 .\n For What it’s Worth Petra Magoni feat. Jean-Jacques Milteau & Manu Galvin .\n Fever......';
...或
textarea = document.getElementById('textInput');
textarea.value = 'Jenny Lewis . Pretty Bird Sergio Mendes & Brasil 66 .\n';
textarea.value = textarea.value + 'For What it’s Worth Petra Magoni feat. Jean-Jacques Milteau & Manu Galvin .\n';
并重复textarea.value = textarea.value +&#39; blablabla \ n&#39;;
答案 5 :(得分:0)
现在你......现在它在点击按钮时调用该功能,但可以轻松更改。
<!DOCTYPE html>
<html>
<body>
<script>
function myFunction() {
var str = "Jenny Lewis . Pretty Bird Sergio Mendes & Brasil 66 .</br> For What it’s Worth Petra Magoni feat. Jean-Jacques Milteau & Manu Galvin .</br> Fever Emiliana Torrini . Me and Amini Cowboy Junkies .</br> Run for your Life Mira Billotte . As I Went out in the Morning Nitin Sawhney feat.</br> Tina Grace . October Daze Isobel Campbell .</br> Saturday’s Gone Barbara . Mes Hommes...;"
var res = str.split("</br>").join("</td></tr><tr><td>");
document.getElementById("demo").innerHTML += "<td>" + res + "</td></tr>";
}
</script>
<p>Click the button to display the array values after the split.</p>
<button onclick="myFunction()">Try it</button>
<style>
table, th, td {
border: 1px solid black;
}
</style>
<table id="demo">
<col width="130">
<tr>
<th>Column 1</th>
</tr>
</table>
</body>
</html>
&#13;