Javascript 使用jQuery从URL页面中的HTML元素读取实时值
我有一个网站: 在这个URL网页中,有一个输入元素,它的HTML id是:“coinyep-input2” 我需要在Visual Studio中使用jQuery读取其值(=大约637.49 ILS) 到目前为止,我什么都试过了,没有成功。 任何帮助都将不胜感激 例如,在jQuery中有一个命令:Javascript 使用jQuery从URL页面中的HTML元素读取实时值,javascript,url,getelementbyid,currency-exchange-rates,Javascript,Url,Getelementbyid,Currency Exchange Rates,我有一个网站: 在这个URL网页中,有一个输入元素,它的HTML id是:“coinyep-input2” 我需要在Visual Studio中使用jQuery读取其值(=大约637.49 ILS) 到目前为止,我什么都试过了,没有成功。 任何帮助都将不胜感激 例如,在jQuery中有一个命令: document.getElementById("coinyep-input2"); ==>我需要做同样的事情,但要从URL页面中获取实时值(汇率)。这有帮助吗 $("#coinyep-input
document.getElementById("coinyep-input2");
==>我需要做同样的事情,但要从URL页面中获取实时值(汇率)。这有帮助吗
$("#coinyep-input2").attr("data-valuta");
或
或
目前,我在C#(服务器)中找到了解决方案,在客户机上使用Razor [基于RSS URL]:
public float getExchangeRate_ETH_To_ILS()
{
float exchangeRate;
string[] words;
int indexOfExchangeRate;
using (var client = new WebClient())
{
try
{
var htmlPage = client.DownloadString("https://coinyep.com/he/rss/ETH-ILS.xml");
words = htmlPage.Split(' ');
indexOfExchangeRate = words.IndexOf("ILS");
exchangeRate = (float)Convert.ToDouble(words[indexOfExchangeRate - 1]);
}
catch(Exception e)
{
exchangeRate = -1;
}
}
return exchangeRate;
}
在客户端,我通过模型(Razor)使用此功能:
但是有一个风险:如果RSS的模板被更改,我们就有麻烦了。我应该把URL粘贴到哪里?对不起,我想我不明白你的问题。我将建议的解决方案粘贴到开发人员控制台中,得到了值。我正在尝试使用Visual Studio阅读它。。。。我的目标是读取这个值并在VisualStudio中使用它。如果在HTML中可以将元素与src(实际上是URL)一起使用,那么必须有一种方法从输入文本元素中读取值。我试图解释我的目标,希望您能理解
$("#coinyep-input2").val();
public float getExchangeRate_ETH_To_ILS()
{
float exchangeRate;
string[] words;
int indexOfExchangeRate;
using (var client = new WebClient())
{
try
{
var htmlPage = client.DownloadString("https://coinyep.com/he/rss/ETH-ILS.xml");
words = htmlPage.Split(' ');
indexOfExchangeRate = words.IndexOf("ILS");
exchangeRate = (float)Convert.ToDouble(words[indexOfExchangeRate - 1]);
}
catch(Exception e)
{
exchangeRate = -1;
}
}
return exchangeRate;
}
var cal1 = @Model.getExchangeRate_ETH_To_ILS();