簡體   English   中英

如何從Onclick Button獲得ID?

[英]How to get ID off Onclick Button?

我想要一個按鈕onclick ID並將其應用於另一個功能。

<input type="button" onclick="recordToFilename();" id="submitdis" value="Enter Discount Price" /> 

並將其應用於

document.getElementById('discounts').innerHTML = "Discount : $" + ( - discountprice).toFixed(2);

請檢查Codepen

感謝幫助

   document.getElementById("submitdis")
   function recordToFilename() {
   var input = document.getElementById('submitdis'),
   discount12 = input.value;

嘗試將參數傳遞給onclick函數

<input type="button" onclick="recordToFilename(this);" id="submitdis" value="Enter Discount Price" /> 


 function recordToFilename(ele)
 {
       console.log(ele.id);
 }

嘗試:

function recordToFilename(e){
   $(this).attr("Id")

  //or:
   e.Id
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM