jQuery在PHP加载后运行 [英] jQuery to run after PHP load

查看:78
本文介绍了jQuery在PHP加载后运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Big Commerce平台的网站上工作.购物车页面内置于PHP调用的代码段中.我无权访问PHP文件.我需要做的是获取span标签的值(在给定索引处)并检索该值,我使用该值来确定我的minQTY文本字段应该是什么.我希望我的代码在页面加载后运行.但是我的脚本在页面上不起作用.

I'm working on a site using the Big Commerce platform. The cart page is built in snippets called by PHP. I don't have access to the PHP files. What I need to do is get the value of a span tag(at a given index) and retrieve the value, I use this value to determine what my minQTY text field should be. I want my code to run after the page has been loaded. However my script isn't working on the page.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">

$(document).load(function(){
            $("a.CustomizeItemLink");
            $changeIndex = $("a.CustomizeItemLink").index('a.CustomizeItemLink');
            $change = $("a.CustomizeItemLink").length;
            $productTestArray = ['/american-boxwood-buxus/', '/lavander-crape-myrtle-lagerstroemia-fs/']
            $productLength = $productTestArray.length;

            for(i=0, j=0; i<=$change, j<=$productLength; i++, j++){
            $productTest = "http://www.tnnursery.net"; 
            $productTestValue = $("td.blah a").get(i);                    
            $productTest = "http://www.blah.net" + $productTestArray[j]; 
            $MD = $productTestValue;
            $MS = $productTest;
            $minQTYArray = ['100','100','75','50','25','20','15'];
            $cartSpanValue = $(".productAttributes td span:eq("+i+")").text();            
            $rdTestArray2 = ['6-12','12-18',"1-2'","2-3'","3-4'","4-5'","5-6'"];
            $arr2Test = jQuery.inArray($cartSpanValue, $rdTestArray2);
            $minQTYValue = $minQTYArray[$arr2Test];
            $cartQtyValue = $(".qtyInput:eq("+i+")").val();

            if($MD != $MS){

            }
            else{    
                if($cartQtyValue >= $minQTYValue){

                }
                else{
                    if ($arr2Test == -1){
                    $cartQtyValue = $(".qtyInput:eq(" + i + ")").val('100');    
                    }
                    else{
                    $cartQtyValue = $(".qtyInput:eq(" + i + ")").val($minQTYValue);  
                    alert($cartQtyValue);
                    }
                }
            }
        }

    });
});
});
    </script>

    </td>
    <td class="ProductName" colspan="1">
        <a href="http://www.blah.net/blah-blah-blah/">Item Name1</a><table class="productAttributes" cellpadding="0" cellspacing="2">
<tr>
<td>
    <label>Plant&#8203; Size&#8203;s:</label>
</td>
<td>
    <span>12-18&#8203;&quot;</span>
</td>

改变
28500 ()

Change
28500 ()

        <div style="display: none" class="WrappingOptions">
            Gift Wrapping:

            <a href="#" onclick="Cart.ManageGiftWrapping('4eea86d587825');" style="">Add</a>
            <span style="display: none">
                (<a href="#" onclick="Cart.ManageGiftWrapping('4eea86d587825');">Change</a> or <a href="cart.php?action=remove_giftwrapping&amp;item_id=4eea86d587825" onclick="return Cart.RemoveGiftWrapping();">Remove</a>)
            </span>
            <br />
            <span style="display: none">
                Gift Message:

            </span>
        </div>
    </td>
    <td align="center" class="CartItemQuantity">
        <span style="padding: 0; margin: 0;"><input type="text" size="2" name="qty[4eea86d587825]" id="text_qty_4eea86d587825" class="qtyInput quantityInput" value="50"/></span>

        <div style="">
            <a href="cart.php?action=remove&amp;item=4eea86d587825" onclick="Cart.RemoveItem('4eea86d587825'); return false;" class="CartRemoveLink">Remove</a>
        </div>
    </td>

我的问题是,如何在将PHP加载到页面后将jQuery设置为运行?

My question is how do I set my jQuery to run after the PHP has been loaded into the page?

推荐答案

尝试将$(document).load替换为$(window).load.

这篇关于jQuery在PHP加载后运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆