jQuery + IP 验证 +在页面重新加载之前,数据不会在恢复时反映出来

发布于 2024-09-04 08:22:39 字数 869 浏览 4 评论 0原文

我正在尝试在我的页面上实施 IP 地址验证。

  1. 我有一个测试框,显示我当前的 IP 地址
  2. 具有相同的隐藏变量

我有两个按钮“保存”和“保存”另一个Revert,On Save将新的IP地址写入DB;在恢复时,我需要将旧的 IP 地址从隐藏变量恢复到可见框。

我正在使用可用的插件@ http://mlntn.com/2009/12/30/jquery-ip-address-plugin/ 进行验证。

这是这个

$(function(){
                $('#ipAddress').ipaddress();
});

(function() {
               $('#cancel')
                .button()
                .click(function() {
                    $("#ipAddress").text($("#oldIPAddress").text());
});

工作正常,但我的文本框 ipAddress 在页面刷新之前不会反映数据:(

    <s:textfield name="ipAddress[abcd][]" id="ipAddress" cssClass="text ui-widget-content ui-corner-all" label="IP Address" value="%{ipAddress}"/>

<s:hidden name="resIpadd" id="resIpadd" value="%{ipAddress}"/>

有没有办法在不刷新页面的情况下反映数据?

I'm trying to implement IP address validation on my page.

  1. I have a test box displaying my current IP address
  2. A hidden variable having the same

I have two buttons Save & the other Revert, On Save the new IP address is written to the DB; on Revert, I need to restore the old IP address from the hidden variable to the visible box.

I'm using the plugin available @ http://mlntn.com/2009/12/30/jquery-ip-address-plugin/ to do my validation.

Here is the

$(function(){
                $('#ipAddress').ipaddress();
});

(function() {
               $('#cancel')
                .button()
                .click(function() {
                    $("#ipAddress").text($("#oldIPAddress").text());
});

This work fine, but my text box ipAddress does not reflect the data until page is refreshed :(

    <s:textfield name="ipAddress[abcd][]" id="ipAddress" cssClass="text ui-widget-content ui-corner-all" label="IP Address" value="%{ipAddress}"/>

<s:hidden name="resIpadd" id="resIpadd" value="%{ipAddress}"/>

Is there a way to get the data to be reflected without refreshing the page?

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

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

发布评论

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

评论(2

萌酱 2024-09-11 08:22:39
(function() {
           $('#cancel')
            .button()
            .click(function() {
                $("#ipAddress").text($("#oldIPAddress").text());
});

该代码会尽快执行,尝试将其移至

$(document).ready(function(){
}

由于您正在访问多个 DOM 元素,因此这些元素可能是
只是在执行代码时无法访问。 jQuery 的 read() 函数
当 DOM 准备就绪时触发。

(function() {
           $('#cancel')
            .button()
            .click(function() {
                $("#ipAddress").text($("#oldIPAddress").text());
});

That code is executed asap, try to move it into

$(document).ready(function(){
}

Since you're accessing several DOM elements, it might be possible that those are
just not accessible at the time that code is executed. jQuery's ready() function
is fired when the DOM is 'ready'.

薯片软お妹 2024-09-11 08:22:39

问题在于它的实现方式,当我们使用插件时

jquery-ip-address-插件

IP 地址文本框在内部分为 4 个不同的文本框,因此,在将其恢复回来时,我们需要使用这 4 个字段。

即使我会创建一个文本框,该插件也会将其拆分。我已经解决了。

感谢您的帮助!

The problem was the way its implemented, when we use the plugin

jquery-ip-address-plugin

The IP address text box is split into 4 different text-boxes internally and hence, while reverting it back, we need to use those 4 fields.

Even though I would have created a single textbox, the plugin splits it. I've resolved it.

Thanks for the help!!

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