如何创建JavaScript关闭链接

    技术2022-07-11  122

    Whenever I create a small JavaScript popup window, I offer a "close" link. Since I'm responsible for the new window, I feel it's my job to help them easily get rid of it.

    每当我创建一个小JavaScript弹出窗口时,我都会提供一个“关闭”链接。 由于我负责新窗口,因此我认为帮助他们轻松摆脱它是我的工作。

    XHTML (The XHTML)

    Create an anchor with the JavaScript "close" call in the "href" attribute:

    使用“ href”属性中JavaScript“ close”调用创建锚点:

    Close Window

    Do not use the onClick attribute of the anchor because not everyone clicks links.

    不要使用锚点的onClick属性,因为不是每个人都单击链接。

    Note: I've gotten out of the habit of using JavaScript popups. They're annoying and as smooth as steel wool. I recommend using a modal box via JavaScript. Most modal box scripts allow for smooth transitions and are just as easy to close as popup windows -- plus, they don't get blocked by popup blockers. I currently use MoodalBox for my projects.

    注意:我已经摆脱了使用JavaScript弹出窗口的习惯。 它们令人讨厌并且像钢丝绒一样光滑。 我建议通过JavaScript使用模式框。 大多数模态框脚本都允许平滑过渡,并且与弹出窗口一样容易关闭-此外,它们不会被弹出窗口阻止程序阻止。 我目前在我的项目中使用MoodalBox 。

    翻译自: https://davidwalsh.name/javascript-close

    Processed: 0.009, SQL: 9