Is it possible to use dynamic variable in ajax? for example this is some of my view

是否可以在ajax中使用动态变量?例如,这是我的一些看法

<div class="col-sm-6 col-xs-12 value">
    <?= form_input(array('name' => 'jenis_anggaran_'.$index, 'id' => 'jenis_anggaran_'.$index, 'readonly' => 'readonly', 'class' => 'required form-control input-sm', 'value' => $this->input->post('jenis_anggaran_'.$index), 'title' => 'Ketik satuan disini', 'rel' => 'Satuan', 'style' => 'width : 100%;', 'placeholder' => 'Satuan')) ?> 
    <span class="red msg_jenis_anggaran_<?=$index?>" id="msg_jenis_anggaran_<?=$index?>"><?=form_error('jenis_anggaran_'.$index,' ',' ')?></span>
</div>

so i need to run a script when jenis_anggaran_$index is change? in static variable i use this script

所以当jenis_anggaran_ $ index改变时我需要运行一个脚本吗?在静态变量中我使用此脚本

$("#propinsi_id").change(function(){
    var propinsi_id = {propinsi_id:$("#propinsi_id").val()};
    $.ajax({
        type: "POST",
        url : "<?php echo site_url('chain/select_kota')?>",
        data: propinsi_id,
        success: function(msg){
           alert("it change");
        }
    });
});

so since my variable is dynamic how can i point those variable in my script?

所以既然我的变量是动态的,我怎么能在我的脚本中指出这些变量呢?

1 个解决方案

#1


-1

If you use template literals, this work will be more simply.

如果您使用模板文字,这项工作将更简单。

like this, `jenis_anggaran_${index}`

像这样,`jenis_anggaran _ $ {index}`

Ref) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

参考)https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

更多相关文章

  1. 将Ajax div内容存储在PHP变量中
  2. Contenteditable / Jquery / Ajax / PHP / mysql - 无法识别URL
  3. Thinkphp中怎么接收GET变量?
  4. thinkphp框架里怎么用linux的crontab写php的定时脚本
  5. 锁定表是否可以通过包含的脚本访问
  6. 确定脚本所在的服务器以及PHP中的配置的最佳方法是什么?
  7. imagecreatetruecolor()在symfony中不起作用,但如果作为php脚本运行
  8. php-fpm通过request_slowlog_timeout检查哪个脚本执行时间长
  9. PHP变量类型+整型类型细节

随机推荐

  1. web.config 配置文件示例详解
  2. ASP.NET Core中的多语言支持的图文详解
  3. C#中关于逆变和协变的详解
  4. MemoryCache问题修复的解决方法
  5. ASP.NET Core Razor页面路由的详细介绍
  6. C#多线程之Semaphore的使用详解
  7. 详解有关asp.net mvc 动态编译生成Contro
  8. C#中Observer观察者模式如何解决牛顿童鞋
  9. C#如何实现JSON与对象之间互相转换功能示
  10. 有关ASP.NET Core 中的多语言支持的详细