jQuery:元素未定义错误(但已定义)

时间:2014-04-12 06:35:02

标签: javascript jquery

我的页面中有一些表单,表单不是硬编码,
所有表格都有名称和唯一ID 但是在调用那些表格时,控制台没有定义 我想用jQuery提交表单,但是表单没有定义,
我尝试过:

alert(jQuery("#paypal_form_-5").length);
//output is 0

document.getElementById('paypal_form_-5').submit();

等。 但是不起作用.......

表单代码

<form target="_blank" action="https://www.paypal.com/cgi-bin/webscr" name="paypal_form_-5" id="paypal_form_-5" method="POST">
            <input type="hidden" value="http://www.domain.com/2014/index.php?option=domain&amp;view=addon_payments&amp;type=return" name="return">
            <input type="hidden" value="2" name="rm">
            <input type="hidden" value="_xclick" name="cmd">
            <input type="hidden" value="rajnvr@rctech.org" name="business">
            <input type="hidden" value="USD" id="paypal_form_currency_code_-5" name="currency_code">
            <input type="hidden" value="http://www.domain.com/2014/index.php?option=domain&amp;view=addon_payments&amp;type=cancel" name="cancel_return">
            <input type="hidden" value="http://www.domain.com/2014/components/domain/views/addon_payments/paypal_ipn.php" name="notify_url">
            <input type="hidden" value="GOLD Membership" name="item_name">
            <input type="hidden" value="20" id="paypal_form_amount_-5" name="amount">
            <input type="hidden" value="http://www.domain.com/2014/components/domain/views/addon_payments/paypal_ipn.php" name="notify_url">
            <input type="hidden" value="001" name="item_number">
            <input type="hidden" value="2740" name="custom">
            <span id="paypal_price_title_-5" class="paypal_price_title">GOLD Membership&nbsp;20&nbsp;USD</span>
            <input type="button" onclick="send_request_to_paypal_express(-5);" value="Pay" name="button_-5">
</form>

1 个答案:

答案 0 :(得分:0)

在HTML下面添加JS或通过

包装你的JS
$(document).ready(function(){/*Your code*/});

演示:http://jsfiddle.net/4c9p7/