从数据库Jquery显示选定的值

时间:2014-12-27 06:04:59

标签: jquery json select

如何显示从数据库返回的年份,2009年,2010年等,这些值在表2中

单独的表Table1具有所选的值。

主要问题是,Table1有YearSelected 2012,但我还需要表2中的2009,2010,2011的值。它必须在JQuery中全部完成吗?有人能指出我一个有效的例子吗?

我是个新手,碰到了一堵砖墙。 THX

<select id="year_selected"  name="YearSelected">
    <option>-Select Year-</option>
    <option>2009</option>
    <option>2010</option>
    <option>2011</option>
    <option>2012</option>
</select>

1 个答案:

答案 0 :(得分:0)

试试这个..

 <select id="year_selected"  name="YearSelected">
        <option>-Select Year-</option>
    </select>
    <script>
    $(document).ready(function() {
       // $('#year_selected').empty();  empty the dropdown (if necessarry)
        $(accounts).each(function(iIndex, sElement) {
            $('#year_selected').append('<option>' + sElement + '</option>');
        });
    });
</script>