我正在尝试在选择选项中传递多个文本。我在这里尝试了很多示例,但是没有用。我哪里错了?
下面是我的代码
<select name="region" id="region" class="region" onchange="change_pack();">
<option selected="selected" value="'Base','abs','Ram'">North</option>
<option value="'Base','noabs','Sita'">South</option>
</select>
下面是我的剧本
function change_pack(pack, table, name){
$.ajax({
type: "POST",
url: "extra/plan.php",
data: "name="+name+"&tble="+table+"&pack="+pack,
cache: false,
success: function(response){
//alert(response);return false;
$("#plan").html(response);
}
});
}
最佳答案
输入值通常是字符串,因此您需要将字符串拆分为值
<select name="region" id="region" class="region" onchange="change_pack(this.value);">
<option selected="selected" value="'Base','abs','Ram'">North</option>
<option value="'Base','noabs','Sita'">South</option>
</select>
js:
function change_pack(data)
{
var [pack, table, name] = data.split(",");
$.ajax({
type: "POST",
url: "extra/plan.php",
data: "name="+name+"&tble="+table+"&pack="+pack,
cache: false,
success: function(response)
{
//alert(response);return false;
$("#plan").html(response);
}
});
}