我想在按钮的 onclick 事件上传递一个值,以便 javascript 可以更新隐藏字段的值。但是我无法将字符串传递给 js 函数
JS
<script>
function sethdnfiletype(filetype)
{
$("#hdnfiletype").val(filetype);
}
</script>
HTML
<asp:ImageButton ID="btn1" runat="server" ToolTip="Upload Report" OnClick="sethdnfiletype(// here I want to send a number like 1 or 2 or 3 //);" href="#uploadTOEFilePopup" data-toggle="modal" ClientIDMode="Static">
最佳答案
您可以使用 onclick 将值发送到函数,只需像通常调用函数一样将它们传入即可。
function clickHandler(amount) {
alert('Clicked with ' + amount);
}
<button type="button" onclick="clickHandler(123);">Click me</button>
关于javascript - 在按钮的 onclick 事件上将字符串传递给 JavaScript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37157796/