这是HTML代码:
<div id="CurrencyQuotePane">
<div class="CurrencyQuote">
<div class="column">
<div class="form-label">Pair: </div><div>1/2</div>
<div class="form-label padding-top">Spread: </div><div>385</div>
</div>
<div class="column">
<div class="form-label">Rate: </div><div>1/2</div>
<div class="form-label padding-top">High/Low: </div><div>2002.0/0.0055</div>
</div>
</div>
<div class="clear"></div>
</div>
如果Javascript中的385不断变化,我如何获得385?
这是我目前的javascript:
function getSpread(){
var tag = iframe.contentDocument.getElementByClassName('SPREAD');
var spread = Number(tag[1].innerHTML);
return spread;
}
很抱歉,如果我对javascript一无所知,我是一个完整的新手。
答案 0 :(得分:5)
将其更改为:
<div class="column">
<div class="form-label">Pair: </div><div>TEXT</div>
<div class="form-label padding-top">SPREAD</div><div id="spreadval">385</div>
</div>
function getSpread(){
var tag = iframe.contentDocument.getElementById('spreadval');
return parseInt(tag.innerHTML);
}
答案 1 :(得分:0)
将id设置为div
<div class="column">
<div class="form-label">Pair: </div><div>TEXT</div>
<div class="form-label padding-top">SPREAD</div><div id="changing_number">385</div>
</div>
使用jquery
$(function(){
var theNumber = parseInt($('#changing_number').text());
});
或使用DOM:
$(function(){
var theNumber = parseInt(document.getElementById('changing_number').innerHTML);
});
在这里你可以学习js:http://www.w3schools.com/jsref/met_doc_getelementbyid.asp
答案 2 :(得分:0)
var column = document.getElementsByClassName('column');
var divs = column[0].getElementsByTagName('div');
alert(divs[1].innerHTML);