This is one line
This is another line
< /code>
What I want to achieve: be able to "trim" the innerHTML value (i.e., remove blank lines) while keeping the formatting. This is simple to do with the innerText value (just something like document.getElementById("id").innerText.trim()
), но форматирование исчезло. Я не вижу никакой ссылки на «обрезать» значение Innerhtml. Есть ли способ сделать это с помощью JavaScript или jQuery?
У меня есть следующая простая довольная довольная табличная ячейка: [i] Когда я нажимаю кнопку Test , он выводит значения innerhtml и innertext внутри. > [code]innerHTML[/code]: (Обратите внимание на 4 теги в конце)[code]This[/i] is one line
This is [u]another[/u] line
< /code> innerText[/code]: [code]This is one line
This is another line
< /code> What I want to achieve: be able to "trim" the innerHTML value (i.e., remove blank lines) while keeping the formatting. This is simple to do with the innerText value (just something like document.getElementById("id").innerText.trim()[/code]), но форматирование исчезло. Я не вижу никакой ссылки на «обрезать» значение Innerhtml. Есть ли способ сделать это с помощью JavaScript или jQuery? [code] function test() { var html = document.getElementById("inputBox").innerHTML; var text = document.getElementById("inputBox").innerText; console.log(`html:\n${html}`); console.log(`text:\n${text}`); }< /code> table { width: 100%; }
У меня есть элемент сетки CSS, и одна из его ячеек содержит предварительно отформатированный код (...). В этом коде могут быть длинные строки, а экраны меньшей ширины могут не поместиться на всю строку. Однако я не хочу разрывать строку, потому что...