gpt4 book ai didi

javascript - 我有一个要求,我需要根据下拉选择显示价格

转载 作者:行者123 更新时间:2023-12-03 02:25:46 24 4
gpt4 key购买 nike

我有一个要求,我需要根据下拉选择显示价格。并且该价格来自相同的db,当我从下拉列表中单击一个测试时,该测试的相关价格应显示在文本框中。该值是从下拉列表中选择选项后绑定(bind)在文本框中,它也在获取跨度后显示,但不显示在文本框中,请告诉我解决方案,因为我只想在文本框中显示它。这是错误图像

enter image description here

模型类

 public partial class TwoDDiagnostic
{
public int TwoD_ID { get; set; }
public string TwoDDiagnostic_Name { get; set; }
public string TwoD_Price { get; set; }
public Nullable<System.DateTime> TwoD_Date { get; set; }
public Nullable<int> centr_Id { get; set; }
}

Controller

 IEnumerable<SelectListItem> selectList2D = from twod in db.TwoDDiagnostics
where twod.centr_Id == Id
select new SelectListItem()
{
Text = twod.TwoDDiagnostic_Name,
Value = twod.TwoDDiagnostic_Name
};
var lasttwoD = db.TwoDDiagnostics.Where(x => x.centr_Id == Id).OrderByDescending(c => c.TwoD_ID).Take(1).FirstOrDefault();
if (lasttwoD == null)
{
ViewBag.twoDID = new SelectList(selectList2D, "Value", "Text");

model.ViewModel_TwoDDiagnostic = null;
return View(model);
}
string twodname = (from sub in db.TwoDDiagnostics where sub.TwoD_ID == lasttwoD.TwoD_ID select sub.TwoDDiagnostic_Name).First();
ViewBag.twoDID = new SelectList(selectList2D, "Value", "Text", twodname);

查看

 <div class="form-inline">
<label for="inputEmail1" class=" col-lg-2 col-sm-4 control-label">2D Diagnostic Services</label>
<div class="col-lg-5">
@Html.DropDownListFor(model => model.PTwoDDiagnostic_name, (SelectList)ViewBag.twoDID, "- Select 2D Diagnostics -", new { @class = "form-control ", @id = "twopID", @onchange = "fill()" })
</div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<div class="col-lg-3">
@*<span class="form-control" id="twoprice"></span>*@
@Html.TextBoxFor(model => model.PTwoDDiagnostic_price, new { @class = "form-control ", @id = "twoprice" , @onchange = "fill()"})


</div>
</div>

这里是json方法

public JsonResult GetTwoDPrice()
{
AllViewModel model = new AllViewModel();
Session["Two_D"] = model.TwoD_ID;
var id = (int)Session["Two_D"];
if (!string.IsNullOrEmpty(Session["Two_D"].ToString()))
{
//int Id = (int)Session["Two_D"];
var Record = (from patient in db.TwoDDiagnostics
where patient.TwoD_ID == id
select new
{
TwoD_ID = patient.TwoD_ID,
TwoD_Price = patient.TwoD_Price
}).FirstOrDefault();
return Json(Record, JsonRequestBehavior.AllowGet);
}

return Json("", JsonRequestBehavior.AllowGet);

}

这是一个脚本

 <script type="text/javascript">
$("#twopID").on('change', function (event) {

$.ajax({
url: "@Url.Action("GetTwoDPrice", "Center")",
type: "Get",
success: function (data) {
debugger;
console.log(data.TwoD_Price);
$('#twoprice').text(data.TwoD_Price);
}
});
});
</script>

最佳答案

您需要使用 jquery val() 方法来设置文本框的值。如果您使用text()方法,它会设置输入元素的innerText(在<input></input> HTML标签之间),该内容仅适用于span、label、h、div等HTML元素。

$('#twoprice').val(data.TwoD_Price);

关于javascript - 我有一个要求,我需要根据下拉选择显示价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48960366/

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