如何:从asp.net输入框动态调用javascript?

发布于 2024-09-14 12:42:54 字数 454 浏览 3 评论 0原文

我有一个 asp.net 输入框:

<asp:TextBox ID="InCL" runat="server" Text=""></asp:TextBox>  

输入数字后,我想将该值发送到更新 google 仪表的 javascript 函数。

例如,用户立即动态输入 77,Google 仪表移动到该位置。

如有任何帮助,我们将不胜感激。
谢谢。

编辑
我正在查看 onkeyup DOM 事件,这是一个好方法吗?

我想我只是在这里自言自语......

I have a asp.net input box:

<asp:TextBox ID="InCL" runat="server" Text=""></asp:TextBox>  

As soon as a number is entered I would like to send that value to a javascript function that updates a google gauge.

For example, user inputs 77, the google gauge immediately dynamically moves to that position.

Any help is appreciated.
Thank You.

EDIT
I'm looking at the onkeyup DOM event, is this a good way to go?

I think I'm just talking to myself on here.....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

划一舟意中人 2024-09-21 12:42:54

这是一个 jQuery 脚本,我曾经做过类似的事情。它确实使用 onkeyup 来设置值;它还使用 onkeydown 来防止非数字值;如果用户尝试让文本框不留任何值,则强制使用默认值 0

var updateUI = function(value) {
    //set gauge
};

var textbox = $('#id_of_textbox)'

textbox.keydown(function(e) {
    return validNumberKeys.indexOf(e.which) > -1;
}).keyup(function(e) {
    var input = $(e.target);
    if(input.val() !== '') {
        updateUI(input.val());
    }
}).blur(function(e) {
    var input = $(e.target);
    if(input.val()==='') { input.val('0'); }
    updateUI(input.val());
});

var validNumberKeys = [8,9,13,16,17,18,35,36,37,38,39,40,45,46,48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105];

Here is a script in jQuery I used to do something very similar. It does indeed use onkeyup to set the value; it also uses onkeydown to prevent non-numeric values; and forces a default value of 0 if the user tries to leave the textbox with no value:

var updateUI = function(value) {
    //set gauge
};

var textbox = $('#id_of_textbox)'

textbox.keydown(function(e) {
    return validNumberKeys.indexOf(e.which) > -1;
}).keyup(function(e) {
    var input = $(e.target);
    if(input.val() !== '') {
        updateUI(input.val());
    }
}).blur(function(e) {
    var input = $(e.target);
    if(input.val()==='') { input.val('0'); }
    updateUI(input.val());
});

var validNumberKeys = [8,9,13,16,17,18,35,36,37,38,39,40,45,46,48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105];
乖乖 2024-09-21 12:42:54

您可以这样做:

<asp:TextBox ID="InCL" runat="server" onchange="YourJavaScriptFunction()" Text=""></asp:TextBox>

YourJavaScriptFunction() 将从 InCL 中读取值并执行您需要执行的操作。

您还可以将值传递给 JavaScript,如下所示: onchange="YourJavaScriptFunction(this.value)"

相同的语法适用于 onkeyup: onkeyup="YourJavaScriptFunction()"

You can do this:

<asp:TextBox ID="InCL" runat="server" onchange="YourJavaScriptFunction()" Text=""></asp:TextBox>

YourJavaScriptFunction() would then read the value out of InCL and do whatever you need to do with it.

You could also pass the value to your JavaScript like this: onchange="YourJavaScriptFunction(this.value)"

The same syntax will work with onkeyup: onkeyup="YourJavaScriptFunction()"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文