0

我正在尝试获取平均租金。我的 yql 代码有效并提供了正确的值,但我试图将其显示在平均租金旁边:但它不起作用。我想也许我获取租金价格的功能放错了地方,或者我错误地处理了变量,但我不知道如何找出来。

    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></    script>
    <script type="text/javascript">
        function evaluateHome() {
            document.getElementById('loading').style.display = 'inline-block';

            var postcode = $('#postcode').val();
            var address = $('#address').val();




            $.get(makeUrl('http://www.realtor.com/propertyrecord-search/' + postcode),
                    function(data) {
                        var context = $('<div />').html($(data).find('content').text());

                        $('#avgDays').html($(context).find('table.summaryTable strong:eq(3)').text());
                         $('#avgList').html($(context).find('table.summaryTable strong:eq(4)').text()
                        + ' - ' + $(context).find('table.summaryTable strong:eq(1)').text());



                    });


       function makeUrl(url) {
            return 'http://query.yahooapis.com/v1/public/yql?q=' +
                    encodeURIComponent('select content from data.headers where url="' + url)
                    + '"&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys'
        }

    </script>




</head>
<body>

    <div>
        <table>
            <tr>
                <td><strong>Please enter postcode: </strong></td>
                <td><input id="postcode" type="text"/></td>
            </tr>
            <tr>
                <td><strong>Please enter address: </strong></td>
                <td><input id="address" type="text"/></td>
            </tr>
          <script>
function handleResponse (json) {
var ul = document.getElementsByTagName( 'ul' )[0],
    avgRent = null;
for ( var i = 0; i < json.query.count; i++ ) {
    avgRent = document.createElement('avgRent');
    avgRent.innerHTML = json.results[i];
     ul.appendChild(avgRent);
}
}
</script>
<script src="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fwww.zillow.com%2Fwidgets%2Fzestimate%2FZestimateSmallWidget.htm%3Fdid%3Dzillow-shv-small-iframe-widget%26type%3Diframe%26forRent%3Dtrue%26address%3D'+ address.replace(/\ /g, '%2B') +'%2B'+postcode+'%22%20and%20xpath%3D'%2F%2Fdiv%5B%40id%3D%22zestimate-rate-container%22%5D%2Fspan%5B2%5D'&callback=handleResponse"></script>  
            <tr>
                <td colspan="2" style="text-align: center;">
                    <button onclick="evaluateHome()">Evaluate!</button>
                    <img id="loading" src="http://www.laneaviation.com/wp-content/themes/laneaviation/images/loading.gif" height="15"/>
                </td>
            </tr>
        </table>
    </div>
    <div>
        <table>
            <tr>
                <td><strong>Avg Marketing Days: </strong></td>
                <td><div id="avgDays"></div></td>
            </tr>
            <tr>
                <td><strong>Estimated Value: </strong></td>
                <td><div id="estimatedVal"></div></td>                    
            </tr>
            <tr>
                <td><strong>Average List: </strong></td>
                <td><div id="avgList"></div></td>                    
            </tr>

            <tr>
                <td><strong>Bedrooms: </strong></td>
                <td><div id="bedrooms"></div></td>                    
            </tr>
            <tr>
                <td><strong>Baths: </strong></td>
                <td><div id="baths"></div></td>                    
            </tr>
            <tr>
                <td><strong>Home Sq Ft: </strong></td>
                <td><div id="homeSize"></div></td>                    
            </tr>
            <tr>
                <td><strong>Lot Sq Ft: </strong></td>
                <td><div id="lotSize"></div></td>                    
            </tr>
            <tr>
                <td><strong>Year Built: </strong></td>
                <td><div id="builtYear"></div></td>                    
            </tr>
            <tr>
                <td><strong>Last Sold Date: </strong></td>
                <td><div id="soldDate"></div></td>                    
            </tr>
            <tr>
                <td><strong>Last Sold Amount: </strong></td>
                <td><div id="soldAmount"></div></td>                    
            </tr>
            <tr>
                <td><strong>Tax Assessed Value: </strong></td>
                <td><div id="taxVal"></div></td>                    
            </tr>
            <tr>
    <td><strong>Average Monthly Rent: </strong></td>
                <td><div id='ul.appendChild(avgRent)'></div></td>
            </tr>
    <tr>
    <td><strong>Better to Sell/Buy or Rent?: </strong></td>
                <td><div id="decision"></div></td>                    
            </tr>
    <tr>
    <td><strong>Add 1 bedroom: </strong></td>
                <td><div id="improveBed"></div></td>                    
            </tr>
    <tr>
    <td><strong>Add 1 bath: </strong></td>
                <td><div id="improveBath"></div></td>                    
            </tr>

        </table>
    </div>
    <script type="text/javascript">
        document.getElementById('loading').style.display = 'none';
    </script>
</body>
</html>
4

1 回答 1

0

evaluateHome()函数似乎没有结束大括号 ( }) 字符。而且,不要忘记在某处调用该函数。

在此处输入图像描述

于 2013-04-22T21:56:50.887 回答