我在一个asp:gridview中添加了一个ButtonLink,它显示一个模型弹出窗口,其中包含一条通知消息和来自所单击行的单元格[1]的文本。其中98%有默认标准消息,即单元格[1]值,但是对于这些注意事项,我想根据单元格[1]中的值显示自定义消息。
我使用这种语法的问题是它始终显示
Gi Joe Destory Cobra
无论row.cells [1]的实际文本是什么。有人可以协助重写,以便它能按我的意愿运作吗?
<script type='text/javascript'>
var row;
function GetSelectedRow(lnk) {
row = lnk.parentNode.parentNode;
var rowIndex = row.rowIndex - 1;
if (row.cells[1].innerHTML = "Green Lantern") {
desc = "Please input villian."
}
if (row.cells[1].innerHTML = "Batman") {
desc = "Stay out of Gotham."
}
if (row.cells[1].innerHTML = "Gi Joe") {
desc = "Destroy Cobra."
}
else { desc = row.cells[1].innerHTML; }
$('#<%=lblText.ClientID %>').text(desc);
$('#myModal').modal('show');
}
</script>
修改
我将我的代码改为
<script type='text/javascript'>
var row;
function GetSelectedRow(lnk) {
row = lnk.parentNode.parentNode;
var rowIndex = row.rowIndex - 1;
if (row.cells[1].innerHTML == "Green Lantern") {
desc = "Please input villian."
}
if (row.cells[1].innerHTML == "Batman") {
desc = "Stay out of Gotham."
}
if (row.cells[1].innerHTML == "Gi Joe") {
desc = "Destroy Cobra."
}
else { desc = row.cells[1].innerHTML; }
$('#<%=lblText.ClientID %>').text(desc);
$('#myModal').modal('show');
}
</script>
但是,例如,如果用户单击用于Gi Joe的ButtonLink而不是desc显示Descroy Cobra,则会显示GI Joe。
答案 0 :(得分:2)
确保 if条件与
if (row.cells[1].innerHTML == "Green Lantern") {
desc = "Please input villian."
}
else if (row.cells[1].innerHTML == "Batman") {
desc = "Stay out of Gotham."
}
else if (row.cells[1].innerHTML == "Gi Joe") {
desc = "Destroy Cobra."
}
else { desc = row.cells[1].innerHTML; }