设置innerHTML输出的样式

发布于 2024-12-23 13:42:52 字数 469 浏览 3 评论 0原文

我正在尝试使用innerHTML函数创建一个JavaScript程序,其中用户在两个文本框中输入某人的名字和姓氏,然后JavaScript在单击按钮后按以下格式操作这些名称:

姓氏、名字。

我已成功让名称按该顺序显示“onclick”,但输出如下所示:

迪克

菲利普

.

我希望一切都在一条线上,不间断。我已经尝试创建一个会影响 div 的 css 类:然而,这不起作用。

到目前为止我正在使用的 HTML 看起来像这样:

    <div id='displayName2'></div>,<div id='displayName1'></div>.

I'm trying to create a JavaScript program using the innerHTML function wherein the user types in the first and last names of somebody in two text-boxes and the the JavaScript manipulates the names after clicking a button to the following format:

Last Name, First Name.

I have successfully gotten the names to appear 'onclick' in that order, but the output looks like this:

Dick

,

Philip

.

I want everything to be on one line without breaks. I have already tried creating a css class that would affect the div: .nobr { white-space:nowrap; } This didn't work, however.

The HTML that I'm working with so far looks like this:

    <div id='displayName2'></div>,<div id='displayName1'></div>.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

瀞厅☆埖开 2024-12-30 13:42:52

要使这两个

标记显示且中间没有换行符,请使用 CSS 属性 display: inline; 或者使用 < /code> 标签而不是

,因为 默认情况下内联显示,其中

是块元素。从语义上讲, 可能更合适。但如果您无法更改 HTML,请相应地修改您的 CSS:

<div id='displayName2'></div>,<div id='displayName1'></div>

#displayName2, #displayName1 {
   display: inline;
}

To get those two <div> tags to appear without a linebreak in between, use the CSS attribute display: inline; Or, use <span> tags instead of <div>, since <span> is displayed inline by default, where <div> is a block element. Semantically, <span> is probably more appropriate., but if you cannot change the HTML, modify your CSS accordingly:

<div id='displayName2'></div>,<div id='displayName1'></div>

#displayName2, #displayName1 {
   display: inline;
}
等待圉鍢 2024-12-30 13:42:52

为此,请使用 代替

如果您坚持使用

,请使用 display: inline 使

呈现为内联元素。

Use <span>s instead of <div>s for this purpose.

If you insist on using <div>s, then use display: inline to make the <div>s render as inline elements.

从此见与不见 2024-12-30 13:42:52

最好使用 而不是

,它也具有中性语义,并且默认是内联的。

Better use <span> instead of <div>, it also has neutral semantic meaning and it's inline by default.

怀里藏娇 2024-12-30 13:42:52

你有两个选择。 div 元素默认为 display: block。使用 span 代替 div,或者使用 display: inline 设置 div 的样式。

You have 2 options. div elements are display: block by default. Either use spans instead of divs or style your divs using display: inline.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文