Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.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 是否有任何类型的方法可以从with node.js调用HTML服务器脚本中的函数?_Javascript_Html_Node.js_Obs - Fatal编程技术网

Javascript 是否有任何类型的方法可以从with node.js调用HTML服务器脚本中的函数?

Javascript 是否有任何类型的方法可以从with node.js调用HTML服务器脚本中的函数?,javascript,html,node.js,obs,Javascript,Html,Node.js,Obs,提前为我缺乏技术语言而道歉 所以,我想做的是在OBS(开放式广播软件)中使用twitch的订阅计数器,我在node.js中制作了一部分,实际计算sub(我实际上让它们保存文本文件中发生的订阅数量)。我缺少的是OBS上显示的部分,这是我用html和CSS制作的实际图形计数器。我这样做是为了在运行node.js文件时,它使用http.createServer().listen(port)函数生成一个本地web服务器(localhost:etc),其中包含html。 问题是,我需要调用一个函数(set

提前为我缺乏技术语言而道歉

所以,我想做的是在OBS(开放式广播软件)中使用twitch的订阅计数器,我在node.js中制作了一部分,实际计算sub(我实际上让它们保存文本文件中发生的订阅数量)。我缺少的是OBS上显示的部分,这是我用html和CSS制作的实际图形计数器。我这样做是为了在运行node.js文件时,它使用
http.createServer().listen(port)
函数生成一个本地web服务器(localhost:etc),其中包含html。 问题是,我需要调用一个函数(
setValue()
),该函数位于HTML文件中的java脚本脚本中,用于更改计数器状态(百分比和填充条)。。。有办法吗

html脚本代码:

<script type="text/javascript">

    let reader = new FileReader();



    class ProgressBar {
        constructor(element, initialValue = 0) {
            this.valueElem = element.querySelector('.progress-bar-value');
            this.fillElem = element.querySelector('.progress-bar-fill');

            this.setValue(initialValue); 
        }

        setValue(newValue) {
            if(newValue < 0){
                newValue = 0;
            }

            if(newValue > 100){
                newValue = 100;
            }

            this.value = newValue
            this.update();
        }

        update() {
            const percentage = this.value + '%';

            this.fillElem.style.width = percentage;
            this.valueElem.textContent = percentage;
        }
    }

    var pb1 = new ProgressBar(document.querySelector('.progress-bar'),50);
</script>

let reader=new FileReader();
类进度条{
构造函数(元素,initialValue=0){
this.valuelem=element.querySelector(“.progress bar value”);
this.fillElem=element.querySelector(“.progress bar fill”);
此.setValue(初始值);
}
设置值(新值){
如果(新值<0){
newValue=0;
}
如果(新值>100){
newValue=100;
}
this.value=newValue
这个.update();
}
更新(){
常量百分比=this.value+'%';
this.fillem.style.width=百分比;
this.valuelem.textContent=百分比;
}
}
var pb1=新的进度条(document.querySelector('.ProgressBar'),50);

您可以使用WebSocket

WebSocket是Web应用程序中HTTP通信的替代方案

它们在客户端和服务器之间提供了一个长寿命的双向通信通道