我正在从服务返回的数组中生成动态单选按钮。返回的每个项目都包含地址数据。我知道如何获取数据的值,但是如何从所选项目中获取所有值?这是我到目前为止所做的:
function showAddresses(item) {
window.addNo2 = item.streetno;
window.addStr2 = item.streetname;
window.addCity2 = item.city;
window.addSt2 = item.state;
window.addZip2 = item.zip;
window.latLong2 = item.latlng;
$('#multiAdds').show();
$('#results').append('<p><input type="radio" name="multiAdds" class="radioButton" onclick="getChecked()" value="' + latLong2 + '">' + addNo2 + ' ' + addStr2 + </p>');
}
function getChecked(){
var latLong2 = $("input[name=multiAdds]:radio:checked").val();
getJurisdictionMulti(latLong2, addNo2, addStr2, addCity2, addSt2, addZip2);
}
我基本上需要能够从所选单选按钮中获取所有相关的地址数据,并使用它们创建单独的变量,以便能够传递到我的getJurisdictionMulti()函数。
答案 0 :(得分:0)
您可以在这种情况下使用HTML-5 数据 - * 属性。 这是一个简单的案例(粗略示例),仍然可以优化..
我们将此属性称为 data-custom
var custom = latLong2 + ',' + addNo2 + ',' + addStr2 + ',' + addCity2
+ ',' + addSt2 + ',' + addZip2 ;
$('#results').append('<p><input data-custom="' + custom + '" type="radio" name="multiAdds" class="radioButton" onclick="getChecked()" value="' + latLong2 + '">' + addNo2 + ' ' + addStr2 + </p>');
function getChecked(){
var values = $("input[name=multiAdds]:radio:checked").data('custom').split(',');
var latLong2 = values[0] ;
var addNo2 = values[1] ;
var addStr2 = values[2] ;
var addCity2 = values[3] ;
var addSt2 = values[4] ;
var addZip2 = values[5] ;
getJurisdictionMulti(latLong2, addNo2, addStr2, addCity2, addSt2, addZip2);
}