jquery多处更新处理


function check_type_message(i){
var ad_index = "#ad_" + i;
if($("#order_budget").val() != "" && $(ad_index + "_cost_dis_input").val() != "" && $("#order_regional").val() != "" && $(ad_index + "_budget_ratio_dis_input").val() != ""){
$.ajax({
url : "<%= check_type_message_orders_path %>",
type : "POST",
data : {order_budget: $("#order_budget").val(), budget_ratio: $(ad_index + "_budget_ratio_dis_input").val(),
ad_platform: $(ad_index + "_ad_platform").val(),
ad_type: $(ad_index + "_ad_type").val(), order_regional: $("#order_regional").val(),
cost_type: $(ad_index + "_cost_type").val(), cost: $(ad_index + "_cost_dis_input").val(),
discount: $(ad_index + "_discount_dis_input").val(), order_budget_currency: $("#order_budget_currency").val()},
success : function(data){
$(ad_index + "_ctr_prediction").text(format_to_numeric(data["ctr_prediction"]) + "%");
$(ad_index + "_cpm_prediction").text(format_to_numeric(data["cpm_prediction"]));
$(ad_index + "_cpc_prediction").text(format_to_numeric(data["cpc_prediction"]));
$(ad_index + "_clicks_prediction").text(format_to_numeric(data["clicks_prediction"]).slice(0, -3));
$(ad_index + "_show_cpc_prediction").text(format_to_numeric(data["clicks_prediction"]).slice(0, -3));
$(ad_index + "_impressions_prediction").text(format_to_numeric(data["impressions_prediction"]).slice(0, -3))
$(ad_index + "_show_cpm_prediction").text(format_to_numeric(data["impressions_prediction"]).slice(0, -3))
$(ad_index + "_general_price").text(format_to_numeric(data["general_price"]));
$(ad_index + "_public_price").text(format_to_numeric(data["public_price"]));
discount_cost_msg(i, data["cost_can"]);
set_discount_val(i);
}
})
}else{
if ($("#order_regional").val() != ""){
$.ajax({
url : "<%= check_type_message_orders_path %>",
type : "POST",
data : {order_budget: $("order_budget").val(), ad_platform: $(ad_index + "_ad_platform").val(),
budget_ratio: $(ad_index + "_budget_ratio_dis_input").val(),
ad_type: $(ad_index + "_ad_type").val(), order_regional: $("#order_regional").val(),
cost_type: $(ad_index + "_cost_type").val(), cost: $(ad_index + "_cost_dis_input").val(),
discount: $(ad_index + "_discount_dis_input").val(), order_budget_currency: $("#order_budget_currency").val()},
success : function(data){
$(ad_index + "_general_price").text(format_to_numeric(data["general_price"]));
$(ad_index + "_public_price").text(format_to_numeric(data["public_price"]));
set_discount_val(i);
}
})
}else{
$(ad_index + "_general_price").text("");
$(ad_index + "_public_price").text("");
}
text_clear = ["ctr_prediction", "cpm_prediction", "cpc_prediction", "clicks_prediction", "show_cpc_prediction", "impressions_prediction", "show_cpm_prediction"]
$.each(text_clear, function( index, value ) {$(ad_index + "_" + value).text("");});
$(ad_index + "_check_cost").html("");
}
show_cost_type(i);
}

def check_type_message
params.delete("action")
params.delete("controller")
params.permit!
@ad = Advertisement.new()
@ad.attributes = params.permit!
@ad.discount = (@ad.cost.to_f / @ad.public_price) * 100
# @ad.discount = params["discount"].to_f / 100 if params["discount"].present?
# @ad.budget_ratio = params["budget_ratio"].to_f / 100 if params["budget_ratio"].present?

impressions_prediction = @ad.impressions_prediction
clicks_prediction = @ad.clicks_prediction
ctr_prediction = @ad.offer.ctr_prediction
general_price = @ad.general_price
cpm_prediction = @ad.cpm_prediction
cpc_prediction = @ad.cpc_prediction
public_price = @ad.public_price

render :json => {
:ctr_prediction => ctr_prediction,
:clicks_prediction => clicks_prediction,
:impressions_prediction => impressions_prediction,
:cpm_prediction => cpm_prediction,
:cpc_prediction => cpc_prediction,
:general_price => general_price,
:public_price => public_price,
:cost_can => @ad.cost_can? }
end


jquery更新select标签:

function set_ad_platform_by_region(){
current_region = $("#order_regional").val();
if($.inArray(current_region, ["US_UK_AU_NZ_MY", "HK_TW_MA_SG", "OTHER_COUNTRY"]) == -1 ){
options = "<option value=" +'COMPUTER' + ">" + 'PC展示广告' + "</option>" + "<option value=" +'MOBILE' + ">" + '移动广告' + "</option>";
}else{
options = "<option value=" +'MOBILE' + ">" + '移动广告' + "</option>";
}
$('.adv_ad_platform').each(function(){
$(this).find('option').remove();
$(this).append(options);
$(this).change();
})
}


$("#chosen_multiple_test").val(["NATION"]).trigger("liszt:updated");
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值