0

我在使用 jquery appendo 插件时遇到问题,我已经克隆了这些字段,但我想根据我从下拉列表中选择的内容填充一个文本字段,我有一个产品下拉列表,当我选择一个时,下一个文本字段必须填写相应的费率。我能够在更改从服务器端带来数据的下拉列表时激活 ajax 事件,但我无法填充相邻的文本字段。这是我的代码。

 <script type="text/javascript" lang="javascript" src="jquery-1.8.2.min.js" ></script>
<script type="text/javascript" lang="javascript" src="jquery.appendo.js" ></script> 
<script type="text/javascript" lang="javascript">
    $(document).ready(function(){

        $('.product').change(function(){
            //ajax call and receiving the data but after getting the data from server how to populate the rate text field
        });
        var id = 0;
        var append = $('#objid').appendo({
        allowDelete: true,
        copyHandlers: true      
    });


});
</script>

这是我的 html 部分。

<body>
    <form action="#" method="post">
    <table id="objid">
        <thead>
            <tr>
                <th>Client:</th>
                <th>Product:</th>
                <th>Rate:</th>
            </tr>
        </thead>
        <tr><td><input type="text" name="name[]"></td>
        <td>
            <select class="product" name="product[]">
                <option value="">---Select---</option>
                <option value="web_designing">Web Designing</option>
                <option value="hosting">Hosting</option>
                <option value="domain">Domain</option>
            </select>
        </td>
        <td><input type="text" name="rate[]" id="rate[]"/></td>
        </tr>

    </table>
    <br>
    <input type="submit" value="Submit" name="submit">
    </form>
</body>
4

1 回答 1

0

在代码部分:

    $('.product').change(function(){
        //ajax call and receiving the data but after getting the data from server how to populate the rate text field
    });

您可以使用以下代码向文本字段添加值:

    $('.product').change(function(){
        //ajax call and receiving the data but after getting the data from server how to populate the rate text field
        var value = ajax_received_value;
        var $this = $(this);
        $this.parent().next().children().val(value);
    });
于 2013-02-15T12:00:01.390 回答