简体   繁体   English

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

[英]jQuery : Element not defined error (but defined)

I have some form in my page,it forms does not hard code, 我的页面中有一些表格,它没有硬编码,
All forms have a name and unique ID. 所有表格都有名称和唯一ID。
But when calling that forms,console sat NOT DEFINED. 但是在调用该表格时,控制台没有被定义。
I want submit forms with jQuery,but forms not defined, 我想用jQuery提交表单,但表单未定义,
I tried with: 我尝试过:

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

and

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

and etc.. But does not work....... 等。但是不起作用.....

form code 表格代码

<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>

Add the JS bellow your HTML or wrap your JS by 在您的HTML下方添加JS或通过以下方式包装JS:

$(document).ready(function(){/*Your code*/});

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM