gpt4 book ai didi

asp.net - 当我向选择添加选项时,选择会变窄

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

继承了一个应用程序,该应用程序的页面有一个调用 javascript 函数 addValueClick() 的链接,当我执行此操作时,会弹出一个对话框,我输入一些文本,然后将文本放入选择框中。每次将新选项添加​​到选择中时,它都会变窄约 5 个像素。我不明白为什么会发生这种情况,但它只发生在 IE7 中

这是 JavaScript:

function addValueClick()
{
var newValue = prompt("Please enter a new value.","");
if (newValue != null && newValue != "")
{
var lst = document.getElementById("lstValues");
var opt = document.createElement("option");
opt.setAttribute("selected", "true");
opt.appendChild(document.createTextNode(newValue));
lst.appendChild(opt);
updateBtns();
copyValues();
}
}

function copyValues()
{
var frm = document.forms[0];
var lst = frm.elements["lstValues"];
var hid = frm.elements["hidValues"];
var xml = "<root>";
for (var i = 0; i < lst.options.length; i++)
{
xml += "<value seq_num=\"" + (i + 1) + "\">" +
lst.options[i].text + "</value>";
}
xml += "</root>";
hid.value = xml;
}

function updateBtns()
{
var lst = document.getElementById("lstValues");
var iSelected = lst.selectedIndex;
var lnkEdit = document.getElementById("lnkEditValue");
var lnkDelete = document.getElementById("lnkDeleteValue");
var lnkUp = document.getElementById("lnkValueUp");
var lnkDown = document.getElementById("lnkValueDown");
if (iSelected == -1)
{
lnkEdit.style.visibility = "hidden";
lnkDelete.style.visibility = "hidden";
lnkUp.style.visibility = "hidden";
lnkDown.style.visibility = "hidden";
}
else
{
lnkEdit.style.visibility = "visible";
lnkDelete.style.visibility = "visible";

if (iSelected == 0)
lnkUp.style.visibility = "hidden";
else
lnkUp.style.visibility = "visible";

if (iSelected == lst.options.length - 1)
lnkDown.style.visibility = "hidden";
else
lnkDown.style.visibility = "visible";
}
}

编辑:HTML,实际上是ASP.NET。 listValueChanged() 方法所做的只是调用上面的 updateButtons()。

<tr>
<TD class=body vAlign=top noWrap align=right><b>Values:</TD>
<TD class=body vAlign=top noWrap align=left><asp:ListBox id="lstValues" runat="server" onchange="lstValuesChange();" Rows="9" onselectedindexchanged="lstValues_SelectedIndexChanged"></asp:ListBox></TD>
<TD class=body vAlign=top noWrap align=left>
<TABLE id="Table2" cellSpacing="2" cellPadding="2" border="0">
<TR>
<TD noWrap>
<asp:HyperLink id="lnkAddValue" runat="server" NavigateUrl="javascript:addValueClick();">Add</asp:HyperLink></TD>
</TR>
<TR>
<TD noWrap>
<asp:HyperLink id="lnkEditValue" runat="server" NavigateUrl="javascript:editValueClick();">Edit</asp:HyperLink></TD>
</TR>
<TR>
<TD noWrap>
<asp:HyperLink id="lnkDeleteValue" runat="server" NavigateUrl="javascript:deleteValueClick();">Delete</asp:HyperLink></TD>
</TR>
<TR>
<TD noWrap>&nbsp;</TD>
</TR>
<TR>
<TD noWrap>
<asp:HyperLink id="lnkValueUp" runat="server" NavigateUrl="javascript:valueUpClick();">Up</asp:HyperLink></TD>
</TR>
<TR>
<TD noWrap>
<asp:HyperLink id="lnkValueDown" runat="server" NavigateUrl="javascript:valueDownClick();">Down</asp:HyperLink></TD>
</TR>
</TABLE>
</TD>
</TR>

最佳答案

它可能与 html 的关系比与脚本的关系更大。 select 包含什么?根据JS,我认为这里没有任何问题。

关于asp.net - 当我向选择添加选项时,选择会变窄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/547457/

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