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
فيشج سأل 7 السنوات
2 إجابات
أفضل رد

Puedes usar el metodo html() مع وظيفة رد الاتصال. 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
جون وقال يجعل 7 السنوات