我正在對距離傳感器進(jìn)行編碼,以從樹莓派讀取數(shù)據(jù)到網(wǎng)站。數(shù)據(jù)必須讀入.txt文件,然后從.txt文件傳輸?shù)骄W(wǎng)站上。我需要幫助來了解如何將.txt文件中的數(shù)據(jù)從字符串轉(zhuǎn)換為整數(shù),以允許我根據(jù)數(shù)據(jù)的數(shù)值更改字體顏色。我嘗試了多種方法,例如嘗試使用Number()方法,但無法弄清楚。<iframe id="textfile" src="SensorData.txt"></iframe><script type="text/javascript">Number(SensorData.txt);function print() {var iframe = document.getElementById('textfile');iframe.contentWindow.print();if(iframe<200){str.fontcolor("red");} else {str.fontcolor("green");}}</script><META HTTP-EQUIV="refresh" CONTENT=".5">結(jié)果應(yīng)顯示html文件上的數(shù)據(jù),該數(shù)據(jù)根據(jù)所計(jì)算的距離不斷刷新并將顏色從紅色更改為綠色。
如何從.txt文件讀取數(shù)據(jù)并將數(shù)據(jù)轉(zhuǎn)換為整數(shù)?
白衣非少年
2021-04-29 13:57:07