我正在尝试将我的Jquery选择下拉列表的选定值设置为隐藏的表单字段。我已经获取所选值,但它只是将隐藏值设置为OBJECT OBJECT。
我是否需要先将其转换为字符串或其他内容?
我正在使用此插件:http://designwithpc.com/Plugins/ddSlick
这是我的代码:
var ddBasic = [
{ text: "House", value: "house", },
{ text: "Condominium", value: "condo", },
{ text: "Office", value: "office", }
];
$('#propertytype').ddslick({
data: ddBasic,
selectText: "Select a property type",
showSelectedHTML : false,
onSelected: function(selectedData){
$("#property_type").val(selectedData);
}
});
var ddBasic2 = [
{ text: "Rent", value: "rent", },
{ text: "Buy", value: "buy", }
];
$('#acquiring').ddslick({
data: ddBasic2,
selectText: "Do you want to buy or rent ?",
showSelectedHTML : false,
onSelected: function(selectedData){
$("#acquire_type").val(selectedData);
}
});
答案 0 :(得分:0)
您将selectedData作为对象。您需要通过
从中获取值selectedData.selectedData.value
因此,使代码看起来更简单,
var ddBasic = [
{ text: "House", value: "house", },
{ text: "Condominium", value: "condo", },
{ text: "Office", value: "office", }
];
$('#propertytype').ddslick({
data: ddBasic,
selectText: "Select a property type",
showSelectedHTML : false,
onSelected: function(selectedObj){
$("#property_type").val(selectedObj.selectedData.value);
}
});
var ddBasic2 = [
{ text: "Rent", value: "rent", },
{ text: "Buy", value: "buy", }
];
$('#acquiring').ddslick({
data: ddBasic2,
selectText: "Do you want to buy or rent ?",
showSelectedHTML : false,
onSelected: function(selectedObj){
$("#acquire_type").val(selectedObj.selectedData.value);
}
});
检查插件网站http://designwithpc.com/Plugins/ddSlick上的第5点