我可以使用 setInterval 来确定使用 dojo 替换元素吗?

发布于 2024-10-02 20:20:12 字数 4680 浏览 1 评论 0原文

有一个地址簿,里面已经有联系人。这就是加载时打开的联系人链接位于页面上的原因。如果用户不想添加当前联系人来填充这些字段,那么一旦他们向字段提供了数据,我希望显示“添加到联系人”按钮。 setInterval 函数是否适合检查用户是否正在这些输入字段中输入新数据?如果是的话我该如何编写dojo代码?

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>
        SAP
    </title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/dojo/1.3.2/dojo/dojo.xd.js" djConfig="parseOnLoad: true">
    </script>
    <script type="text/javascript">

        dojo.addOnLoad(function(){ 
            dojo.require("dijit.form.Button");
            dojo.require("dijit.form.TextBox");
        });

    </script>
    <style type="text/css">
        #prelims {
            position: relative;
            float: left;
            margin-right: 10px;
            margin-bottom: 5px
        }

        #addToContacts {
            position: relative;
            float: left;
            display: none;
        }

        #nameWrap {
            position: relative;
            clear: left;
        }

    </style>
</head>
<body>
    <form>
        <div id="prelims" class="checksVertical">
            <span id="" class="button-link pill-btn">
                <span class="hasHover">
                    <a id="open-contacts" class="buttons" target="" href="#">
                        Open Contacts
                    </a>
                </span>
            </span>
        </div>
        <div id="addToContacts" class="checksVertical">
            <span class="button-link pill-btn">
                <span class="hasHover">
                    <div id="addNewContact" class="hide">
                        <form method="post" id="addContactHide">
                            <input class="buttons" id="addContact" type="submit" value="Add Contact" /><input type="hidden" id="hiddenFName" name="tFName" value=""/><input type="hidden" id="hiddenLName" name="tLName" value=""/><input type="hidden" id="hiddenCompany" name="tCompany" value""/>
                        </form>
                    </div>
                </span>
            </span>
        </div>
        <div id="nameWrap">
            <div class="input-inline">
                <label id="for-tFName" for="tFName">
                    <span class="required">
                        *
                    </span>First Name
                </label>
                <div class="input-text-wrapper input-text-lg">
                    <span class="input-cap-left">
                    </span>
                    <span class="input-field">
                        <input type="text" id="tFName" name="tFName" maxlength="50" />
                    </span>
                    <span class="input-cap-right">
                    </span>
                </div>
            </div>
            <div class="input-inline last">
                <label id="for-tLName" for="tLName">
                    <span class="required">
                        *
                    </span>Last Name
                </label>
                <div class="input-text-wrapper input-text-lg">
                    <span class="input-cap-left">
                    </span>
                    <span class="input-field">
                        <input type="text" id="tLName" name="tLName" maxlength="50" />
                    </span>
                    <span class="input-cap-right">
                    </span>
                </div>
            </div>
            <div class="clearfix">
            </div>
        </div>
        <div id="tCompanyWidget">
            <label id="for-tCompany" for="tCompany">
                <span class="required">
                    *
                </span>Company Name
            </label>
            <div class="input-text-wrapper input-text-lg">
                <span class="input-cap-left">
                </span>
                <span class="input-field">
                    <input type="text" id="tCompany" name="tCompany" maxlength="50" />
                </span>
                <span class="input-cap-right">
                </span>
            </div>
        </div>
    </form>
</body>

There is an address book that already has contacts. That is why the open contacts link is on the page when it loads. If the user does not want to add a current contact to populate these fields then once they have supplied data to the fields I want the add to contacts button to appear. Would a setInterval function be appropriate to check to see if the user is entering new data into these input fields? If so how would I write the dojo code?

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>
        SAP
    </title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/dojo/1.3.2/dojo/dojo.xd.js" djConfig="parseOnLoad: true">
    </script>
    <script type="text/javascript">

        dojo.addOnLoad(function(){ 
            dojo.require("dijit.form.Button");
            dojo.require("dijit.form.TextBox");
        });

    </script>
    <style type="text/css">
        #prelims {
            position: relative;
            float: left;
            margin-right: 10px;
            margin-bottom: 5px
        }

        #addToContacts {
            position: relative;
            float: left;
            display: none;
        }

        #nameWrap {
            position: relative;
            clear: left;
        }

    </style>
</head>
<body>
    <form>
        <div id="prelims" class="checksVertical">
            <span id="" class="button-link pill-btn">
                <span class="hasHover">
                    <a id="open-contacts" class="buttons" target="" href="#">
                        Open Contacts
                    </a>
                </span>
            </span>
        </div>
        <div id="addToContacts" class="checksVertical">
            <span class="button-link pill-btn">
                <span class="hasHover">
                    <div id="addNewContact" class="hide">
                        <form method="post" id="addContactHide">
                            <input class="buttons" id="addContact" type="submit" value="Add Contact" /><input type="hidden" id="hiddenFName" name="tFName" value=""/><input type="hidden" id="hiddenLName" name="tLName" value=""/><input type="hidden" id="hiddenCompany" name="tCompany" value""/>
                        </form>
                    </div>
                </span>
            </span>
        </div>
        <div id="nameWrap">
            <div class="input-inline">
                <label id="for-tFName" for="tFName">
                    <span class="required">
                        *
                    </span>First Name
                </label>
                <div class="input-text-wrapper input-text-lg">
                    <span class="input-cap-left">
                    </span>
                    <span class="input-field">
                        <input type="text" id="tFName" name="tFName" maxlength="50" />
                    </span>
                    <span class="input-cap-right">
                    </span>
                </div>
            </div>
            <div class="input-inline last">
                <label id="for-tLName" for="tLName">
                    <span class="required">
                        *
                    </span>Last Name
                </label>
                <div class="input-text-wrapper input-text-lg">
                    <span class="input-cap-left">
                    </span>
                    <span class="input-field">
                        <input type="text" id="tLName" name="tLName" maxlength="50" />
                    </span>
                    <span class="input-cap-right">
                    </span>
                </div>
            </div>
            <div class="clearfix">
            </div>
        </div>
        <div id="tCompanyWidget">
            <label id="for-tCompany" for="tCompany">
                <span class="required">
                    *
                </span>Company Name
            </label>
            <div class="input-text-wrapper input-text-lg">
                <span class="input-cap-left">
                </span>
                <span class="input-field">
                    <input type="text" id="tCompany" name="tCompany" maxlength="50" />
                </span>
                <span class="input-cap-right">
                </span>
            </div>
        </div>
    </form>
</body>

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

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

发布评论

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

评论(1

多彩岁月 2024-10-09 20:20:12

我认为输入字段上的 onChange 或 onBlur 事件比 setInterval 更好。由于这些存在于常规输入 html DOM 节点上,因此没有必要使用 dojo。

编写一个可以在多个输入字段上重复使用的 JavaScript 函数:

var show_add_to_contact = function(){
  dojo.byId("prelims").style.display = "none";
  dojo.byId("addToContacts").style.display = "block";
};

然后您可以直接在 html DOM 节点上使用它:

<input type="text" id="tFName" name="tFName" maxlength="50" onChange="show_add_to_contact();" />

或者您可以在创建 dijit TextBox 时以编程方式分配它

new dijit.form.TextBox({"onChange":show_add_to_contact,"name":"tFName"}, "tFName");

I think that either onChange or onBlur events on the input fields are better to use then setInterval. Since these exists on the regular input html DOM nodes, it is not necessary to use dojo.

Write a javascript function that can be re-used on several input fields:

var show_add_to_contact = function(){
  dojo.byId("prelims").style.display = "none";
  dojo.byId("addToContacts").style.display = "block";
};

Then you can either use it directly on the html DOM node:

<input type="text" id="tFName" name="tFName" maxlength="50" onChange="show_add_to_contact();" />

or you can assign it programmatically when creating dijit TextBox

new dijit.form.TextBox({"onChange":show_add_to_contact,"name":"tFName"}, "tFName");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文