Jquery 如何将js变量传递给drupal php变量?
我想将一个js变量传递给drupal php变量并显示其值。 下面是我的代码Jquery 如何将js变量传递给drupal php变量?,jquery,drupal,Jquery,Drupal,我想将一个js变量传递给drupal php变量并显示其值。 下面是我的代码 $form['title'] = array( '#type' => 'select', '#title' => t('titles'), '#page callback' => 'drupal_get_form', '#page arguments' => array('test_select'), '#access callback' => TRUE, '#op
$form['title'] = array(
'#type' => 'select',
'#title' => t('titles'),
'#page callback' => 'drupal_get_form',
'#page arguments' => array('test_select'),
'#access callback' => TRUE,
'#options' => $options,
'#prefix' => '<div>',
'#postfix' => '</div>',
'#attributes' => array('onchange' => 'test_change')
);
$form['titletext'] = array(
'#type' => 'textfield',
'#title' => 'title',
);
drupal_add_js('$('.$form['title']['select'].').change(function () {
var str ="";
'.$a.' = "";
$("'.$form['title']['select'].' option:selected").each(function () {
str += $(this).text() + " ";
});
})
.change();', 'inline', 'header');
我想将该str变量分配给textfield值,或者简单地将该变量分配给drupal php变量并显示在页面上。我不了解php,但关于textfield,您可以试试这个
$('#textBoxId').val(str);
我想把一个js变量传递给drupal php变量并显示它的值 使用DOM操作。。喜欢要显示结果的区域执行以下操作 $select.changefunction{ $thevalue.html$this.val }
或者在你的情况下。。输出文本时,将显示每个。如果您需要drupal来获取值。。你必须服从后端。。像使用ajax等我输入了$'titletext'.valstr;但它不起作用。titletext是我的文本字段的id。您可以在上面的代码中看到它。现在我想根据下拉列表中的选择从数据库中检索日期。我已经编写了$titletext.changefunction{$title.html$this.val},但它不起作用。titletext是textfield的id,title是下拉框的id现在我想根据下拉列表中的选择从数据库中检索日期。