duanlv2788 2013-01-09 10:09
浏览 49
已采纳

从Smarty PHP循环(JQuery)中的select中获取选项值

So I need to append and un-append divs which contain the values of whichever option was selected, problem is that the method of displaying the select values in the first place is via. a for-each loop using Smarty PHP templates, and I am unable to find any documentation on how it can be achieved using this.

What I've tried: as you will see below I've tried creating a JavaScript variable inside the template file, but it only ever returns the value of the first option selected. I cannot figure out why I am only ever getting the first value taken from the loop.

For example, if I have two items in a select 'A' and 'B', when selecting the value option, I will always just receive 'A' back as the value.

Smarty Template Code:

<select class="my_select" name="vlans_{$NetworkDTO->id}[]">
    {foreach from=$arrNetworkDTO item=NetworkDTO name=arr}
    <option class="addOvmCardList" id="addNameDisk{$strIdTpl}" value="{$NetworkDTO->name|escape}">{$NetworkDTO->name}</option>
    {/foreach}
</select>

JQuery Code:

$('a.addListOVM').click(function(){

    $(".my_select").change(function() {

        $('.addCardOVM').append(
              '<div class="divform"><label>' + $(this).val() + '</label>' +
              '<a href="">-</a></div>'
                );              
    });                             

});

Any help is appreciated.

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥20 苹果app名字侵权商标,我投诉了,但是苹果一直没回怎么办
      • ¥15 Android studio运行不成功总是报错
      • ¥15 pycharm 加载软件包列表时出错connect timed out
      • ¥20 数字方面的问题,请给个思路
      • ¥15 和您碰到了同一个问题
      • ¥15 如何在微信支付V3PHP版请求中添加header?
      • ¥15 在数字信号处理中用MATLAB显示波形。
      • ¥15 keil MDK软件进行仿真调试的局限
      • ¥15 关于gateway产生临时文件夹的问题
      • ¥15 Java Broken Pipe以及OOM