获取选择名称的值可以通过以下几种方式:
示例代码: HTML部分:
<select id="mySelect">
<option value="option1">选项1</option>
<option value="option2">选项2</option>
<option value="option3">选项3</option>
</select>
JavaScript部分:
var selectElement = document.getElementById("mySelect");
var selectedValue = selectElement.value;
console.log(selectedValue);
示例代码:
@RestController
public class MyController {
@GetMapping("/myEndpoint")
public String myEndpoint(@RequestParam("myParam") String selectedValue) {
System.out.println(selectedValue);
return selectedValue;
}
}
示例代码(使用MySQL):
CREATE TABLE myTable (
id INT PRIMARY KEY AUTO_INCREMENT,
selectedValue VARCHAR(255)
);
INSERT INTO myTable (selectedValue) VALUES ('option1'), ('option2'), ('option3');
SELECT selectedValue FROM myTable WHERE id = 1;
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云