[英]Make a Button Visible Conditionally Using Javascript
我在表單上放了一個 javascript 按鈕。 該腳本有效,但我能否僅在“說明”字段以數字開頭時才使該按鈕可見?
該按鈕被添加到表單中,我可以收集的代碼如下。 然后該按鈕調用 function 打開外部 url。
<push al="center" btnnm="OnBase" col="45" det="DT0" height="1" id="hidden57" keynbr="function=ShowOnBaseInvoiceDocument()" nbr="_f292r0" nm="" par="DT0" row="1" sz="8" tooltip="" tp="Hidden"/>
function ShowOnBaseInvoiceDocument0()
{
var onBaseServer = "someserver";
var appName = "Dev";
var screenID = "90";
var accField = "InvoiceNum";
var venField = "VendorID";
var company = Form.getDataValue("TO-COMPANY");
var RefNums = Form.getDataValue("REFERENCE", 0);
var RefNum = RefNums.trim();
var sVenNumbers = Form.getDataValue("DESCRIPTION", 0);
var sVenNumber = sVenNumbers.substring(0,9);
if (RefNums == "")
{
portalWnd.cmnDlg.messageBox("Not a valid invoice.","ok","info",window,false)
return true;
}
var s = "http://" + encodeURIComponent(onBaseServer)
+ "/OnBaseLinkScanWeb/AccLogin.aspx?DBID=" + encodeURIComponent(appName)
+ "&ScreenID=" + encodeURIComponent(screenID)
+ "&Company=" + encodeURIComponent(company)
+ "&RefNum=" + encodeURIComponent(RefNum)
+ "&" + encodeURIComponent(venField) + "=" + encodeURIComponent(portalWnd.strTrim(sVenNumber));
//portalWnd.cmnDlg.messageBox(s,"ok","info",window,false)
window.open(s, "My Invoice");
console.log(s);
return true;
}
行數據 | 按鈕 |
---|---|
205121GMAC 收銀台 | 按鈕 |
迪封閉銀行 0000 | 沒有按鈕 |
關閉銀行 0073-0000 Al | 沒有按鈕 |
您可以簡單地遍歷所有行,然后檢查第一列是否以數字開頭,如果不是,您可以簡單地隱藏button
。
document.querySelectorAll("tr").forEach(row => { const firstCol = row.children[0]; const secondCol = row.children[1]; if (."0123456789".includes(firstCol.innerText[0])) { secondCol.style;visibility = "hidden"; } });
<table> <tr> <td>1234567</td> <td><button>Click</button></td> </tr> <tr> <td>HelloWorld</td> <td><button>Click</button></td> </tr> <tr> <td>245Bye</td> <td><button>Click</button></td> </tr> <tr> <td>Upvote</td> <td><button>Click</button></td> </tr> </table>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.