我想将id传递给字符串,但总是会出错
var c = document.getElementById("predefinedMessage");
var id= c.selectedIndex;
var text= "{{ form.predefinedMessage.vars.choices[id].data.message }}";
$('message').val(text);
});
我如何在文本变量中传递id
答案 0 :(得分:0)
如果您选择的元素是下拉列表,我建议您使用jQuery以下代码:
// Select by the ID predefinedMessage
var dropDown = $("select#predefinedMessage");
// Get the selected index from the dropdown
var selectedIndex = dropDown.find("option:selected").index();
var text = "{{ form.predefinedMessage.vars.choices[" + selectedIndex + "].data.message }}";
$('message').val(text);