将本地文本文件中的文本显示到div中? (没有网络服务器) [英] Display text from local text file into a div? (No webserver)

查看:98
本文介绍了将本地文本文件中的文本显示到div中? (没有网络服务器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Twitch流媒体,我目前正在尝试以动画方式为流中的任何文本设置动画.我使用一种称为流标签的东西,它从流中获取最新信息,并将其作为.txt文件输出到我的PC上的文件夹中.

I am a Twitch streamer and I am currently trying to animate any text on my stream the way I want it animated. I use a thing called stream labels, which gets the latest information from my stream, and outputs it to a folder on my pc as a .txt file.

我想做的是在div中调用.txt文件,对其进行样式设置,然后通过OBS browsersource使用该文件.我使它具有动画效果,并且确实显示了文本,但是无法找到一种样式设置样式(对象中的内容)的方式.我对JS感到很糟糕,并且我读到无法使用JS调用本地文件.有什么我可以用来实现这一目标的吗?

What I am trying to do is to call upon the .txt file in a div, style it, and use the file by using OBS browsersource. I have it animated and it does display the text, but cant figure out a way to style it (the content within the object). I am terrible with JS, and I have read that you cannot call upon local files with JS. Is there anything that I could use to make this happen?

这就是我拥有的:

 <head>
    <link rel="stylesheet" href="style.css">
    <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
</head>

<body>


<div id="element-animation">
</div>


<script>
document.getElementById('element-animation').innerHTML += '<object type="text/html" data="most_recent_follower.txt"></object>';
</script>

<script>
</script>


</body>

问题是,使用这种方法与使用html中的object标记没有什么不同,并且对象的内容无法设置样式.

The problem is, using this way would be no different then just using the object tag in the html, and the object content cannot be styled.

推荐答案

您需要学习javascript的基础...特别是有关AJAX的知识.

You need to learn the basic of javascript... Specially about AJAX.

要将文件中的所有内容都放入文档中,您需要使用ajax-要使用ajax,您可能需要一台服务器,除非关闭了一些安全标志.

To get everything from a file into your document you need to use ajax - to use ajax you probably need a server unless some security flags is turned off.

jQuery(function($){
  $.get("most_recent_follower.txt", function(txt) {
    $('#element-animation').text(txt)
  })
})

这篇关于将本地文本文件中的文本显示到div中? (没有网络服务器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆