onclick 事件 - 使用 id 以外的其他内容调用按钮

发布于 2024-11-27 20:41:38 字数 1223 浏览 3 评论 0原文

当用户单击按钮时,我试图重新运行 JavaScript 块。该网站是在 CMS 中创建的,因此我无法访问为其提供 ID 的按钮。然而,在萤火虫中我注意到它有这些值 ->

<input type="submit" value="Continue">

无论如何,我可以通过使用“继续”的值来调用它吗?

仅供参考:该按钮是用 php 编码的,我想重新运行以下代码

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>

<script type="text/javascript">
    $(window).load(function resizePole(){
    var ht=($('#LayoutColumn2').height() > $('#LayoutColumn3').height()) ?
    $('#LayoutColumn2').height() : $('#LayoutColumn3').height(); $('#lightPole').height(ht); }); </script>

,我尝试使用以下方法调用它:

onclick="return resizePole();"

哦,我对 javascript 几乎一无所知:)

链接到正在处理的页面 - 您可能必须创建一个客户帐户。输入一些胡言乱语,我可以稍后将其删除

网站链接

有什么问题是:好的,让我解释一下应该发生什么。我创建了一个名为“lightpole”的 div,该 div 包含一个灯杆的背景图像,该图像使用 javascript 进行编码,以在页面加载时匹配“content”div 的高度。在 checkout_express 页面上,CMS 系统的创建者创建了可扩展和可折叠的 div 来引导用户完成结帐过程。在第三步“送货方式”中,用户单击“继续”按钮,该按钮展开“订单确认步骤”。此 div 导致“内容”div 比初始加载时长,但灯杆的大小仅匹配内容的初始高度,而不是订单确认步骤的添加高度,因此它导致灯杆比实际短需要。

I am trying to rerun a block of javascript when the user clicks on a button. The site was created in a CMS so I do not have access to the button to give it an id. However, in firebug I noticed it has these values ->

<input type="submit" value="Continue">

Is there anyway I can call to this by using the value of 'Continue'?

FYI: the button is coded with php and I want to rerun the following

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>

<script type="text/javascript">
    $(window).load(function resizePole(){
    var ht=($('#LayoutColumn2').height() > $('#LayoutColumn3').height()) ?
    $('#LayoutColumn2').height() : $('#LayoutColumn3').height(); $('#lightPole').height(ht); }); </script>

and I am attempting to call this using:

onclick="return resizePole();"

Oh and I know next to nothing about javascript :)

Link to page working on - you may have to create a customer account. Enter some jibberish and I can delete it later

link to site

What the problem is: Ok let me explain what should be happening. I have created a div called 'lightpole' this div contains a background image of a lightpole that is coded with javascript to match the height of the 'content' div when the page loads. On the checkout_express page the creators of the CMS system have created expanding and collapsible divs that guide the user through the checkout process. On the third step 'Shipping Method' the user clicks on the 'Continue' button which expands the 'Order Confirmation Step'. This div causes the 'content' div to be longer than on initial loading but the lightpole was only sized to match the inital height of the content, not the added height of the Order Confirmation Step so it causes the lightpole to be shorter than it actually needs to be.

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

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

发布评论

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

评论(1

红焚 2024-12-04 20:41:38

这会起作用。

$('[type="submit"][value="Continue"]').click(function () {
{
    return resizePole();
});

编辑

正如评论中指出的,有一种更简洁的方法可以做到这一点。我通常出于习惯而使用上述方法(这样可以更轻松地向点击事件添加未来的逻辑)。

$('[type="submit"][value="Continue"]').click(resizePole);

编辑2

要回答评论中的问题 - 是的,您也可以按 div ID 进行过滤。这将附加到 ID 为 DivIdHere 且值为Continue 的 div 内所有提交按钮的单击事件。

$('#DivIdHere [type="submit"][value="Continue"]').click(resizePole);

编辑3

这有点脏,但是在查看了您更新的要求之后,这应该可以解决问题。基本上,它将点击事件添加到页面上值为“继续”的最后一个提交按钮(根据您提供的链接,这似乎是运输部分)。

$('[type="submit"][value="Continue"]:last').click(resizePole);

This will work.

$('[type="submit"][value="Continue"]').click(function () {
{
    return resizePole();
});

EDIT

As pointed out in the comments, there is a more concise way to do this. I typically use the method above out of habit (makes it easier to add future logic to the click event).

$('[type="submit"][value="Continue"]').click(resizePole);

EDIT 2

To answer the question in the comments - yes, you can filter by the div ID as well. This will attach to the click event of all submit buttons inside a div with an id of DivIdHere and a value of Continue.

$('#DivIdHere [type="submit"][value="Continue"]').click(resizePole);

EDIT 3

This is a bit dirty, but after looking at your updated requirments, this should do the trick. Basically, it adds the click event to the last submit button on the page that has a value of continue (which appears to be the shipping section based on the link you provided).

$('[type="submit"][value="Continue"]:last').click(resizePole);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文