我有一个表单,我想用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') }}");
}
使用此代码,我收到一个错误:
变量“allRecordsActions”不存在。
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') }}");
}