📜  在 onchange 事件中使用数据选择器(将选项属性传递给选择 onchange) - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:39.288000             🧑  作者: Mango

代码示例1
function myFunction(sel) {
  var opt = sel.options[sel.selectedIndex];
  var price = opt.dataset.price
  document.getElementById("demo").innerHTML = "You selected: " + price;
}

Select a new car from the list.

When you select a new car, a function is triggered which outputs the value of the selected car.