Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript函数在div中显示_Javascript_Html_Scripting - Fatal编程技术网

javascript函数在div中显示

javascript函数在div中显示,javascript,html,scripting,Javascript,Html,Scripting,我创建了一个javascript并完成了所有需要的编码,最后得到了一个变量“bookerVar”。我希望这个变量显示在我的html页面的底部。我该怎么做呢 (更详细的解释:我创建了一个页面,用户可以从下拉列表中进行选择,就像使用javascript从下拉列表中进行选择一样。我进行某些计算,最后将最后一个值存储在名为bookerVar的变量中,该变量位于名为bookersay()的函数中 函数的最后一行表示return bookerVar 现在我想要的是,存储在bookerVar中的值可以在我的h

我创建了一个javascript并完成了所有需要的编码,最后得到了一个变量“bookerVar”。我希望这个变量显示在我的html页面的底部。我该怎么做呢

(更详细的解释:我创建了一个页面,用户可以从下拉列表中进行选择,就像使用javascript从下拉列表中进行选择一样。我进行某些计算,最后将最后一个值存储在名为bookerVar的变量中,该变量位于名为bookersay()的函数中

函数的最后一行表示return bookerVar

现在我想要的是,存储在bookerVar中的值可以在我的html页面的bootom中以div标记显示)。
谁能告诉我,我必须在html代码和javascript(实际上是在不同的文件中)中编写什么。谢谢。

告诉你的最简单的事情是获得,然后使用以下内容:

$("body").append("<div>" + bookerVar + "</div>");
$(“body”).append(“+bookerVar+”);

最简单的方法是获取,然后使用以下内容:

$("body").append("<div>" + bookerVar + "</div>");
$(“body”).append(“+bookerVar+”);

将其放入BookerBar当前所在的
.html
文档中

<script type="text/javascript">
    function addDiv() {
        var div = document.createElement('div');
        div.innerHTML = bookerVar;
        document.getElementsByTagName('body')[0].appendChild(div);
    }
    addDiv();
</script>

函数addDiv(){
var div=document.createElement('div');
div.innerHTML=bookerVar;
document.getElementsByTagName('body')[0].appendChild(div);
}
addDiv();

将其放入BookerBar当前所在的
.html
文档中

<script type="text/javascript">
    function addDiv() {
        var div = document.createElement('div');
        div.innerHTML = bookerVar;
        document.getElementsByTagName('body')[0].appendChild(div);
    }
    addDiv();
</script>

函数addDiv(){
var div=document.createElement('div');
div.innerHTML=bookerVar;
document.getElementsByTagName('body')[0].appendChild(div);
}
addDiv();

看看我创建的示例是否适合您。您可以在一些.html文件中复制/粘贴并运行它

<html>
<head>
<title>Appending content to some div</title>
</head>     
<body>
<div id="content"></div>
</body>
<html>

<script type="text/javascript">
function appendToContent(html) {
    var content = document.getElementById('content');
    var div = document.createElement('div');
    div.innerHTML = html;
    content.appendChild(div);
}

appendToContent('hello world');
</script>

将内容附加到某个div
函数附件内容(html){
var content=document.getElementById('content');
var div=document.createElement('div');
div.innerHTML=html;
内容。附加子项(div);
}
附录内容(“hello world”);

看看我创建的示例是否适合您。您可以在一些.html文件中复制/粘贴并运行它

<html>
<head>
<title>Appending content to some div</title>
</head>     
<body>
<div id="content"></div>
</body>
<html>

<script type="text/javascript">
function appendToContent(html) {
    var content = document.getElementById('content');
    var div = document.createElement('div');
    div.innerHTML = html;
    content.appendChild(div);
}

appendToContent('hello world');
</script>

将内容附加到某个div
函数附件内容(html){
var content=document.getElementById('content');
var div=document.createElement('div');
div.innerHTML=html;
内容。附加子项(div);
}
附录内容(“hello world”);


我们可以看到脚本吗?它实际上不完整,现在没有什么意义,但我会稍后上传它,以便将来如果有人来到此页面,它可能会有帮助。我们可以看到脚本吗?它实际上不完整,现在没有什么意义,但我会稍后上传它,以便将来如果有人来到此页面,这可能会有帮助,没有提到jquery..?实际上,纯DOM在我看来会更容易。我只知道足够的javascript来做我之前提到的事情。我正在使用教程学习javascript,对jquery一无所知。不过还是要谢谢。这里没有提到jquery…?事实上,在我看来纯DOM会更容易。我只知道足够的javascript来做我之前提到的事情。我正在使用教程学习javascript,对jquery一无所知。但是还是要谢谢。我还需要在html文件中的div标记中做任何我想让它显示的事情吗??不,根据
bookerVar
是什么,我建议用
标记或
标记包围它。我还需要在html文件中的div标记中做任何我想让它显示的事情吗??不,根据
bookerVar
是什么,我建议用
标记或
标记围绕它。我的javascript在另一个页面上有一个小问题,你也可以用变量bookerVer解释一下,我不理解var div=document.createElement('div')之后的脚本;这只是一个“通用”的例子。createElement('div')创建了一个新元素,即div,接下来,它会向其添加一些html。如果要附加BookServer变量的值,只需调用appendToContent(BookServer)。当然,您可能需要做一些更改以使此代码适应您的页面。实际上,我正在通过教程学习javascript,所以我只知道很少的东西。所以我所要做的就是将最后一行代码替换为appendToContent(bookerVar)??非常感谢您的帮助。是的,但我不知道您的代码是如何构造的,您可能需要对我的代码做一些细微的更改。我的javascript在另一个页面上有一个小问题,请您使用变量BookServer解释一下,我不理解var div=document.createElement('div')之后的脚本;这只是一个“通用”的例子。createElement('div')创建了一个新元素,即div,接下来,它会向其添加一些html。如果要附加BookServer变量的值,只需调用appendToContent(BookServer)。当然,您可能需要做一些更改以使此代码适应您的页面。实际上,我正在通过教程学习javascript,所以我只知道很少的东西。所以我所要做的就是将最后一行代码替换为appendToContent(bookerVar)??非常感谢您的帮助。是的,但我不知道您的代码是如何构造的,您可能需要对我的代码做一些细微的更改。