gpt4 book ai didi

JavaScript 只读问题

转载 作者:行者123 更新时间:2023-12-01 15:50:33 27 4
gpt4 key购买 nike

我正面临 JavaScript 只读字段的问题。我有一个我正在只读的文本框。

 if(val == true)
{
ddlCnt.value=objRec.iCntId;
tAdd1.value=objRec.sAddress1;
tAdd2.value=objRec.sAddress2;
tCity.value=objRec.sCity;
tState.value=objRec.sState;
tZip.value=objRec.sZip;

//tAdd1.disabled = tAdd2.disabled = tCity.disabled = tState.disabled = tZip.disabled = ddlCnt.disabled = true;
//tAdd1.disabled = tAdd2.disabled = tCity.disabled = tState.disabled = tZip.disabled = ddlCnt.disabled = true;
tAdd1.setAttribute("readonly", true);
tAdd2.setAttribute("readonly", true);
tCity.setAttribute("readonly", true);
tState.setAttribute("readonly", true);
tZip.setAttribute("readonly", true);
}

它工作正常。
现在停用我使用的这个只读属性
else
{
tAdd1.value = tAdd2.value = tCity.value = tState.value = tZip.value = "";
//tAdd1.disabled = tAdd2.disabled = tCity.disabled = tState.disabled = tZip.disabled = ddlCnt.disabled = false;
ddlCnt.value="-1";
vsRec.innerHTML='';
tAdd1.setAttribute("readonly", false);
tAdd2.setAttribute("readonly", false);
tCity.setAttribute("readonly", false);
tState.setAttribute("readonly", false);
tZip.setAttribute("readonly", false);

//vsRec.style.visibility='hidden';
}

但它根本不起作用。任何人都可以帮助我解决这个问题,或者任何可以帮助我解决这个问题的建议或提示(以及为什么这不起作用?)。

最佳答案

您需要使用 removeAttribute 删除该属性.

tAdd1.removeAttribute("readonly");
tAdd2.removeAttribute("readonly");
tCity.removeAttribute("readonly");
tState.removeAttribute("readonly");
tZip.removeAttribute("readonly");

关于JavaScript 只读问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6068332/

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