我只是想知道这是否可能,假设我有:
<select name = 'region' id = 'region'>
<option value = '1'>Region 1</option>
<select>
现在,我知道当我选择“区域 1”时,我得到的值为 1。有没有办法得到 将“区域 1”作为值本身,而不更改值 = '1'。我需要它用于其他下拉菜单的 JavaScript。
抱歉我忘记说了,我指的是 PHP。我知道:
$value = $_POST['region'];
如果值为 1,我怎样才能只传递 $_POST 的文本?
最佳答案
var el = document.getElementById('region');
var text = el.selectedIndex == -1 ? null : el.options[el.selectedIndex].text;
console.log(text);
关于javascript - 下拉菜单选择获取文本值而不是分配的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23288370/