gpt4 book ai didi

javascript - jquery 两次选择的 select 选项无法正常工作

转载 作者:行者123 更新时间:2023-12-03 04:09:57 25 4
gpt4 key购买 nike

$(".treatment-btn").click(function()
{
$("#treatmentModal").modal('show');
$('.treatment-form')[0].reset();
$('#treatmentModal #treatment_time option').removeAttr("selected");
$('#treatmentModal #treatment_time option[value=""]').attr("selected", "selected");
}); //when i click on this button it resets form successfully but select option is not reset.

function makeEditHtml(response) {
var price = response[0].treatment_price.split(".")[0];
var cent = response[0].treatment_price.split(".")[1];
$("#treatmentModal #treatment").val(response[0].treatment_name);
$("#treatmentModal #price").val(price);
$('#treatmentModal #cent option[value='+cent+']').attr("selected", "selected");
$('#treatmentModal #treatment_time option').removeAttr("selected");
$('#treatmentModal #treatment_time option[value='+response[0].treatment_duration+']').attr("selected", "selected"); //i select it again at here after ajax call
$.each(response, function(i)
{
$("#treatmentModal input[type=checkbox][value="+response[i].worker_id+"]").prop("checked",true);
});
$("#treatmentModal").modal('show');
}

//当 ajax 请求触发时调用此函数,我以相同的形式附加数据,但未选择选择框值。它在 firebug 中显示正确,但未显示在屏幕上。第一次运行良好

最佳答案

将您的点击功能代码更改为以下。要重置选择,您只需将其值设置为空白即可。

$(".treatment-btn").click(function()
{
$("#treatmentModal").modal('show');
$('.treatment-form')[0].reset();
$('#treatmentModal #treatment_time').val("");
});

相应地更改其他代码。希望对您有帮助!

关于javascript - jquery 两次选择的 select 选项无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44369475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com