我有一个表单,我想用js变量改变它的作用路径。
这是当前的工作代码:
if ($('#totalRecordsOfQuery').val() < 100) {
$('#postbackform').attr('action', "{{ path('_getAllRecordsStudentsProgress') }}");
$('#postbackform').submit();
$('#postbackform').attr('action', "{{ path('xyz) }}");
}
我想要类似的东西:
var allRecordsActions = "_getAllRecordsStudentsProgress";
if ($('#totalRecordsOfQuery').val() < 100) {
$('#postbackform').attr('action', "{{ path(allRecordsActions) }}");
$('#postbackform').submit();
$('#postbackform').attr('action', "{{ path('xyz') }}");
}
使用此代码,我收到错误消息:
变量&#34; allRecordsActions&#34;不存在。
答案 0 :(得分:0)
var allRecordsActions = "_getAllRecordsStudentsProgress";
var concatenation= '{{ path("'+ allRecordsActions +'") }}';
if($('#totalRecordsOfQuery').val()<100){
$('#postbackform').attr('action', concatenation);
$('#postbackform').submit();
$('#postbackform').attr('action', "{{ path('xyz') }}");
}
或
var allRecordsActions = "_getAllRecordsStudentsProgress";
if($('#totalRecordsOfQuery').val()<100){
$('#postbackform').attr('action', '{{ path("'+ allRecordsActions +'") }}');
$('#postbackform').submit();
$('#postbackform').attr('action', "{{ path('xyz') }}");
}