[英]How to get <select> value with javascript?
如何从php获取价值并通过php发送价值? 可以输入文字,但我无法获得价值。 我只需要通过ajax和php通过电子邮件发送值。
HTML代码
<div class="input">
<input type="text" name="height" placeholder=""/>
</div>
<div class="input">
<select name="select">
<option value="1">one</option>
<option value="2">two</option>
</select>
</div>
<div class="input">
<select name="selectt">
<option value="3">three</option>
<option value="4">four</option>
</select>
js代码
var user_height = $(this).find("input[name='height']").val();
var user_select = $(this).find("input[name='select']").val();
var user_selectt = $(this).find("input[name='selectt']").val();
var ok_send = $(this).find('.results_send_form');
//getting values
$.ajax({
url: "send.php",
type: "post",
dataType: "json",
data: {
"height": user_height,
"select": user_select,
"selectt": user_selectt,
}
替换您的代码
var user_height = $(this).find("input[name='height']").val();
var user_select = $(this).find("input[name='select']").val();
var user_selectt = $(this).find("input[name='selectt']").val();
至
var user_height = $(this).find("input[name='height']:selected").val();
var user_select = $(this).find("input[name='select']:selected").val();
var user_selectt = $(this).find("input[name='selectt']:selected").val();
您没有名为select
或selectt
的输入,这是选择菜单。 我不知道this
在您的代码中指的是什么,因为您没有包含上下文,但是您需要使用select[name='select']
或select[name='selectt']
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.