【问题标题】:How can I use html tag in this javascript? [duplicate]如何在这个 javascript 中使用 html 标签? [复制]
【发布时间】:2014-10-05 16:23:35
【问题描述】:

如何在这个 javascript 中使用 html 标签?

首先,为什么<br> 在提示符下不起作用。其次,为什么我不能使用<h1><h2><h3>...或<div style="......">等css或html代码对这段代码(poundOne.pound)使用标签来使字体变大?

<html>
<head>
<script type="text/javascript">


function poundToKgConvertor( pound ){
    this.pound = pound;
    this.convertorDon = convertor;
}
function convertor(){
    var convert = this.pound * 0.453592;
    return convert;
}

var poundOne = new poundToKgConvertor(prompt ("Convert Pound to Kilogram!<br> Please insert your    number of pound!"));
</script>

</head>

<body>

<script type="text/javascript">


document.write(poundOne.pound +  " Pound = " + poundOne.convertorDon() + " <b>Kilogram</b>");

</script>

</body>
</html>

【问题讨论】:

  • prompt 函数只接受纯文本。
  • 哪个 JS 不工作 - var poundOnedocument.write

标签: javascript html css oop


【解决方案1】:

您不能在提示/警告对话框中使用 HTML。但是您可以使用换行符:

prompt ("Convert Pound to Kilogram!\n Please insert your number of pound!");

【讨论】:

  • 谢谢!但有人知道我的第二个问题吗?
  • 抱歉,秒的问题是什么?为什么你不能在那里使用 HTML?答案:因为提示/警报不是 HTML 结构的一部分,所以它不是 DOM。
  • 是的,我知道它不是 HTML 的一部分。第二个问题:为什么我不能通过使用css或html代码(如

    ...或
    ?

猜你喜欢
相关资源
最近更新 更多
热门标签