gpt4 book ai didi

javascript - 我想在 javascript 中获取没有 ClientId 的变量中的元素

转载 作者:行者123 更新时间:2023-12-03 08:09:46 25 4
gpt4 key购买 nike

我想获取“textbox”变量中没有 ClientId 的元素

        function fncInputDateTimeOnly() {
var textBox = document.getElementById("MainContent_txtFilingStartDate");
var textLength = textBox.value.length;
if (textLength >= 10) {
event.returnValue = false;
}

<asp:TextBox ID="txttDate" onkeypress="fncInputDateTimeOnly()" runat="server" Width="195px" />

上面的代码工作完美,但我想这样做,但它不起作用

 function fncInputDateTimeOnly() {
var textBox = this; //how to get the element in variable
var textLength = textBox.value.length;
if (textLength >= 10) {
event.returnValue = false;
}

最佳答案

this 作为参数传递给该方法。

<asp:TextBox ID="txttDate" onkeypress="fncInputDateTimeOnly(this)" runat="server" Width="195px" /> 
function fncInputDateTimeOnly(textBox) {
var textLength = textBox.value.length;
...

关于javascript - 我想在 javascript 中获取没有 ClientId 的变量中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34198286/

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