EspañolDeutschFrançaisItalianoPortuguêsРусскийΕλληνικά日本語中文(简体)हिन्दी; हिंदीالعربية
既定の言語として設定します。
PF の質問 - フォーラム

どのように私は、タグ内のタグでこれらのスペースを交換できますか。 ?

¿Cómo puedo reemplazar, dentro de una etiqueta <label>, 、 espacios existentes por etiquetas <Br/>?. たとえば, tengo lo siguiente:

<label>Aquí va algún texto</label>

y quiero cambiarlo por:

<label>Aquí<br/>va<br/>algún<br/>texto</label>

Lo he intentando con:

$('label').html().replace(' ', '<br/>');

pero no me funciona.

Share on Facebook Tweet about this on Twitter Share on Google+ Pin on Pinterest Share on Reddit Share on VK Share on StumbleUpon Share on Tumblr Share on LinkedIn Email this to someone Print this page
FishGG 聞かれるは 7 年
2 回答
最高の答え

Puedes usar el metodo html() con una función de callback. Para los espacios en blanco puedes usar una expresión regular en el método replace().

$('label').html(function(i, oldHTML) {
   return oldHTML.replace(/\s+/g, '<br/>');
}

 

Share on Facebook Tweet about this on Twitter Share on Google+ Pin on Pinterest Share on Reddit Share on VK Share on StumbleUpon Share on Tumblr Share on LinkedIn Email this to someone Print this page
Borja いう 7 年

この方法を試してみてください:

$('label').html($('label').html().replace(' ', '<br/>'));
Share on Facebook Tweet about this on Twitter Share on Google+ Pin on Pinterest Share on Reddit Share on VK Share on StumbleUpon Share on Tumblr Share on LinkedIn Email this to someone Print this page
JuanR いう 7 年