gpt4 book ai didi

javascript - 不显示 div,因为传递的参数(值)的行为就像字符串而不是 div id

转载 作者:行者123 更新时间:2023-11-28 15:35:01 24 4
gpt4 key购买 nike

JavaScript 中存在问题,点击时未显示所需的 div,因为传递的参数是值(AWB 的 ID),但它的行为类似于字符串 value

View.cshtml

@foreach (var item in Model)
{
<tr>
<td>@item.AWBNO
</td>
<td>@item.AIRLINENAME
</td>
<td>@item.CARGODATE
</td>
@foreach (var itema in entity)
{


if (itema.AWBNo == @item.AWBNO)
{
Filled = true;
DCNo = itema.DCNumber;
break;
}
else
{
Filled = false;
}
}
<td>
@if (!Filled)
{
@Html.ActionLink(" ", "AddOn", "Section82", new { instanceId = item.AWBId }, new { @class = "AddOn" })
}
@if (Filled)
{
<div id = @item.AWBId style="display: none;" >
MyTextOnClick</div>
<button onclick = "Show(value)" value = @item.AWBId>
ClickMe</button>
}
</td>
</tr>
}

JS:

<script type = "text/javascript">
function Show(value)
{
alert(value);
$("#value").show(); // here is the major problem it's not getting id although in alert it showing the right id.
}
</script>

主要问题是它没有获取要显示的 div id,尽管在警报中它显示了正确的 AWBId 请帮助。

最佳答案

使用时需要将值连接到#

function Show(value) 
{
alert(value);
$("#"+value).show();
}

编辑:为您的评论添加代码

HTML:

<button class="some-class-name" value = @item.AWBId>
ClickMe
</button>

JQuery:

$('.some-class-name').on('click', function(){
var id = $(this).attr('value');
$("#"+id).show();
});

由于您使用的是 JQuery,因此您可以执行类似于编辑的操作。

关于javascript - 不显示 div,因为传递的参数(值)的行为就像字符串而不是 div id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25928507/

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