我有一个在 cakephp 中创建的表单中的地址列,其中我们有永久地址和当前地址,其中要填写地址、国家、州、城市字段。如下图所示
如图所示,有一个选择框(同上),用于将所有地址字段(地址、国家、州、城市)从当前地址克隆到具有相同地址的永久地址。我们只使用印度的州所以我们在州选择框中默认设置了印度和所有印度州,所以我们只能在用户选择州后通过 ajax 调用城市选项,代码 //Function for select city
function get_city(UserProfileState)
{
var state_id=document.getElementById('UserProfileState').value;
$.ajax({
type: "GET",
url: "get_city",
data: "UserProfileState="+state_id,
success: function(msg){
$("#city").html(msg);
}
});
}
//克隆所有地址字段的功能
$("#chkform").click(function()
{
if($(this).is(":checked"))
{
$("#UserProfilePeraddress").val($("#UserProfilePaddress").val());
$("#UserProfilePcountry").val($("#UserProfileCountry").val());
$("#UserProfilePstate").val($("#UserProfileState").val());
$("#UserProfilePcity").val($("#UserProfileCity").val());
$("#UserProfilePpincode").val($("#UserProfilePcode").val());
$("#UserProfilePtelephone").val($("#UserProfileTelephone").val());
}}
当我从页面 get_city.ctp 的 ajax 调用更新值时,但是当我克隆字段时它仍然没有从城市字段中获取值,克隆 pcity 在选择框中显示空选项。