通过Javascript触发asp:TextBox的ontextchanged()事件
我有一个asp:TextBox,如下所示通过Javascript触发asp:TextBox的ontextchanged()事件,javascript,c#,ajax,event-handling,dom-events,Javascript,C#,Ajax,Event Handling,Dom Events,我有一个asp:TextBox,如下所示 <asp:TextBox runat="server" AutoPostBack="True" ID="txtG1" ontextchanged="txtG1_TextChanged" onmouseout="javascript:RefreshIt(this)"/> <script type="text/javascript"> function RefreshIt(selectObj) { __doP
<asp:TextBox runat="server" AutoPostBack="True" ID="txtG1" ontextchanged="txtG1_TextChanged" onmouseout="javascript:RefreshIt(this)"/>
<script type="text/javascript">
function RefreshIt(selectObj) {
__doPostBack('<%= Page.ClientID %>', selectObj.name);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" AutoPostBack="True" ID="txtG1" OnTextChanged="txtG1_TextChanged"
onmouseout="javascript:RefreshIt(this);" />
<br />
<br />
Text Changed:
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
</body>
任何帮助都将不胜感激。请参阅:
<script type="text/javascript">
function RefreshIt(selectObj) {
__doPostBack('<%= Page.ClientID %>', selectObj.name);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" AutoPostBack="True" ID="txtG1" OnTextChanged="txtG1_TextChanged"
onmouseout="javascript:RefreshIt(this);" />
<br />
<br />
Text Changed:
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
</body>
通过这个链接,我找到了一些和你想要的结果相同的东西。不确定这是否适合您的应用程序,但它可以工作:
<script type="text/javascript">
function RefreshIt(selectObj) {
__doPostBack('<%= Page.ClientID %>', selectObj.name);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" AutoPostBack="True" ID="txtG1" OnTextChanged="txtG1_TextChanged"
onmouseout="javascript:RefreshIt(this);" />
<br />
<br />
Text Changed:
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
</body>
Aspx:
将RefreshIt函数更改为使用参数执行回发:
<script type="text/javascript">
function RefreshIt(selectObj) {
__doPostBack('<%= Page.ClientID %>', selectObj.name);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" AutoPostBack="True" ID="txtG1" OnTextChanged="txtG1_TextChanged"
onmouseout="javascript:RefreshIt(this);" />
<br />
<br />
Text Changed:
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
</body>
见:
<script type="text/javascript">
function RefreshIt(selectObj) {
__doPostBack('<%= Page.ClientID %>', selectObj.name);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" AutoPostBack="True" ID="txtG1" OnTextChanged="txtG1_TextChanged"
onmouseout="javascript:RefreshIt(this);" />
<br />
<br />
Text Changed:
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
</body>
通过这个链接,我找到了一些和你想要的结果相同的东西。不确定这是否适合您的应用程序,但它可以工作:
<script type="text/javascript">
function RefreshIt(selectObj) {
__doPostBack('<%= Page.ClientID %>', selectObj.name);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" AutoPostBack="True" ID="txtG1" OnTextChanged="txtG1_TextChanged"
onmouseout="javascript:RefreshIt(this);" />
<br />
<br />
Text Changed:
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
</body>
Aspx:
将RefreshIt函数更改为使用参数执行回发:
<script type="text/javascript">
function RefreshIt(selectObj) {
__doPostBack('<%= Page.ClientID %>', selectObj.name);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" AutoPostBack="True" ID="txtG1" OnTextChanged="txtG1_TextChanged"
onmouseout="javascript:RefreshIt(this);" />
<br />
<br />
Text Changed:
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
</body>
为什么不简单地将textbox的AutoPostBack属性设置为true,它会在每次文本更改时自动回发,从而触发textchanged事件
<script type="text/javascript">
function RefreshIt(selectObj) {
__doPostBack('<%= Page.ClientID %>', selectObj.name);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" AutoPostBack="True" ID="txtG1" OnTextChanged="txtG1_TextChanged"
onmouseout="javascript:RefreshIt(this);" />
<br />
<br />
Text Changed:
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
</body>
简单为什么不简单地将textbox的AutoPostBack属性设置为true,每次文本更改时它都会自动回发,从而触发textchanged事件
<script type="text/javascript">
function RefreshIt(selectObj) {
__doPostBack('<%= Page.ClientID %>', selectObj.name);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" AutoPostBack="True" ID="txtG1" OnTextChanged="txtG1_TextChanged"
onmouseout="javascript:RefreshIt(this);" />
<br />
<br />
Text Changed:
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
</body>
简单的
<script type="text/javascript">
function RefreshIt(selectObj) {
__doPostBack('<%= Page.ClientID %>', selectObj.name);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" AutoPostBack="True" ID="txtG1" OnTextChanged="txtG1_TextChanged"
onmouseout="javascript:RefreshIt(this);" />
<br />
<br />
Text Changed:
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
</body>
//JavaScript中的OnTextChanged适用于IE、Firefox、Edge、Chohme、Safari和Opera
//我的英语不是很好,我的母语是格曼语
Html.:
var秒表1
功能秒表{
ifAktion==ende{
var ende=window.sessionStorage.getItem'Mytime'
window.sessionStorage.removietem'Mytime'
clearIntervalstopwatches1
返回ende;
}
ifAktion==weiter{
var MyTime1=window.sessionStorage.getItem'Mytime'
MyTime1++
变量MyTime2=MyTime1+9
window.sessionStorage.setItem'Mytime',MyTime2
}
}
函数焦点FunctionMyField,myFieldvalue{
ifdocument.onlineform.OnFocus\u start.value==0{
document.onlineform.OnFocus\u start.value=1
document.onlineform.OnFocus\u startup\u value.value=myFieldvalue
}
;}
函数KeydUpFunctionmyField,myFieldvalue,iput{
ifmyFieldvalue!=document.onlineform.OnFocus\u start\u value.value&&document.onlineform.OnFocus\u start.value==1{
document.onlineform.OnFocus\u start.value=2
window.sessionStorage.setItemiput,new Date.getTime
stopwatches1=setIntervalfunction{stopwatchweiter},10;
}
否则{;
ifmyFieldvalue==document.onlineform.OnFocus\u startup\u value.value&&document.onlineform.OnFocus\u startup.value==2{
document.onlineform.OnFocus\u start.value=1
clearIntervalstopwatches1
艾特格利希
};}
;}
函数模糊函数MyInput{
document.onlineform.OnFocus\u start.value=0
document.onlineform.OnFocus\u startup\u value.value=
var field16=秒表终端;
field16=field16/1000
window.sessionStorage.removietemmyinput
alertzz+field16
ifield16
//JavaScript中的OnTextChanged适用于IE、Firefox、Edge、Chohme、Safari和Opera
//我的英语不是很好,我的母语是格曼语
Html.:
var秒表1
功能秒表{
ifAktion==ende{
var ende=window.sessionStorage.getItem'Mytime'
window.sessionStorage.removietem'Mytime'
clearIntervalstopwatches1
返回ende;
}
ifAktion==weiter{
var MyTime1=window.sessionStorage.getItem'Mytime'
MyTime1++
变量MyTime2=MyTime1+9
window.sessionStorage.setItem'Mytime',MyTime2
}
}
函数焦点FunctionMyField,myFieldvalue{
ifdocument.onlineform.OnFocus\u start.value==0{
document.onlineform.OnFocus\u start.value=1
document.onlineform.OnFocus\u startup\u value.value=myFieldvalue
}
;}
函数KeydUpFunctionmyField,myFieldvalue,iput{
ifmyFieldvalue!=document.onlineform.OnFocus\u start\u value.value&&document.onlineform.OnFocus\u start.value==1{
document.onlineform.OnFocus\u start.value=2
window.sessionStorage.setItemiput,new Date.getTime
stopwatches1=setIntervalfunction{stopwatchweiter},10;
}
否则{;
ifmyFieldvalue==document.onlineform.OnFocus\u startup\u value.value&&document.onlineform.OnFocus\u startup.value==2{
document.onlineform.OnFocus\u start.value=1
clearIntervalstopwatches1
艾特格利希
};}
;}
函数模糊函数MyInput{
document.onlineform.OnFocus\u start.value=0
document.onlineform.OnFocus\u startup\u value.value=
var field16=秒表终端;
field16=field16/1000
window.sessionStorage.removietemmyinput
alertzz+field16
如果满足正常引发ontextchanged事件的条件,则iffield16 ontextchanged会正确激发。我很难让onmouseout事件同时引发强制ontextchanged事件。好的,我明白你的意思。我做了一个简单的项目并进行了一些测试。我用我的发现更新了我的答案。谢谢你的帮助。这让我朝着正确的方向前进。当满足正常引发ontextchanged事件的条件时,ontextchanged会正确激发。我很难让onmouseout事件也引发强制引发ontextchanged事件。好的,我明白你的意思。我做了一个简单的项目并做了一些测试。我用我的发现更新了我的答案。感谢h这让我朝着正确的方向前进。这不是自动回发的问题。问题是关于在asp:textbox上使用java脚本ontextchange事件。。
因为OnTextChanged不是这样工作的。控件也需要失去焦点才能触发事件。这不是自动回发的问题。问题是关于在asp:textbox上使用java脚本ontextchange事件。因为ontextchange不是这样工作的。控件还需要失去焦点才能触发事件。