是否可以在ajax中使用动态变量?
16lz
2021-01-22
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
更多相关文章
- 将Ajax div内容存储在PHP变量中
- Contenteditable / Jquery / Ajax / PHP / mysql - 无法识别URL
- Thinkphp中怎么接收GET变量?
- thinkphp框架里怎么用linux的crontab写php的定时脚本
- 锁定表是否可以通过包含的脚本访问
- 确定脚本所在的服务器以及PHP中的配置的最佳方法是什么?
- imagecreatetruecolor()在symfony中不起作用,但如果作为php脚本运行
- php-fpm通过request_slowlog_timeout检查哪个脚本执行时间长
- PHP变量类型+整型类型细节