gpt4 book ai didi

javascript - 无法在 Razer 中使用 JavaScript

转载 作者:行者123 更新时间:2023-12-03 05:07:41 26 4
gpt4 key购买 nike

我在 cshtml 中有以下 View 端代码

<div class="item-grid">

@foreach (var product in Model.Products)
{
var itemboxid = "item-box_" + @product.Id;

<div class="item-box" style="display:none;" id="@itemboxid">

@Html.Partial("_ProductBox_Category", product)

</div>

}

</div>

默认内容是隐藏的。我正在尝试使用以下 JavaScript 取消隐藏内容

    $(document).ready(function () {

$("#search-box-button").click(function () {

var city = $('#city').val();

var serchterm = $('#small-searchterms1').val();

@foreach(var product in Model.Products)
{


@:if(city==@product.city)
{

var pro_id = "#item-box_" + product.Id;

@:$("@pro_id").show();



}


}

});
});

#city 是我们可以输入文本数据的文本框的 id 值但这段代码无法正常工作请帮我解决这个问题

最佳答案

我通常使用<text>标签(并在最后修复了您的产品 ID - 看起来您将 js 和 razor 变量混淆了):

 $(document).ready(function() {

$("#search-box-button").click(function() {

var city = $('#city').val();
var serchterm = $('#small-searchterms1').val();

@foreach(var product in Model.Products) {

<text>
if (city == '@product.city') {
var pro_id = "#item-box_@product.Id";

$(pro_id).show();
}
</text>

}

});
});

关于javascript - 无法在 Razer 中使用 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41956746/

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