gpt4 book ai didi

javascript - 如何从 asp net C# 中单击按钮后的代码调用 javascript 函数?

转载 作者:太空宇宙 更新时间:2023-11-03 22:55:46 24 4
gpt4 key购买 nike

这是我的 Javascript 函数:

<script type="text/javascript">

function SelectionTextBox()
{

document.getElementById("TextBox1").select();

}

</script>

这里我调用按钮上的函数:

ScriptManager.RegisterClientScriptBlock(this, GetType(), "t ", "SelectionTextBox();", true);

我想在单击按钮时选择我的 TextBox1 中的文本,但它不起作用。

最佳答案

var selectButton = document.getElementById("mySelectBtn");
var textBox = document.getElementById("myTextBox");
selectButton.addEventListener('click', SelectionTextBox = function(){

textBox.focus();
textBox.select();

});
<input type='button' id='mySelectBtn' value='Select'/>
<input type='text' id='myTextBox' value='testString'/>

尝试使用此代码通过隐藏代码 (C#) 处理 Javascript 函数:

Page.ClientScript.RegisterStartupScript(this.GetType(),"CallMyFunction","SelectionTextBox();",true);

相反:

ScriptManager.RegisterClientScriptBlock(this, GetType(), "t ", "SelectionTextBox();", true);

JavaScript 应该是:

var input = document.getElementById('myTextInput');

input.focus();
input.select();

关于javascript - 如何从 asp net C# 中单击按钮后的代码调用 javascript 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45447722/

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