-2

这是 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?

这是我当前的 javascript:

function getSpread(){
    var tag = iframe.contentDocument.getElementByClassName('SPREAD');
    var spread = Number(tag[1].innerHTML);
    return spread;
}

对不起,如果我对javascript一无所知,我是一个完整的新手。

4

3 回答 3

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);
}
于 2013-04-13T08:13:26.280 回答
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

于 2013-04-13T08:17:04.590 回答
0
var column = document.getElementsByClassName('column');
var divs = column[0].getElementsByTagName('div');
alert(divs[1].innerHTML);
于 2013-04-13T08:18:18.733 回答