English 中文(简体)
为什么不把我的草率法典称作?
原标题:Why is my jquery code not being called?
  • 时间:2011-11-23 19:43:38
  •  标签:
  • jquery

我的守则如下:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <script src="Scripts/jquery-1.7.js" type="text/javascript"></script>
        <script>
                    $( target ).submit(function() 
                    {
                    alert( Handler for .submit() called. );
                   });
        </script>

    </head>
    <body>
        <form id="target" method="post">
            <input type="text" value="Hello there" />
            <input type="submit" value="Go" />
        </form>
        <div id="other">
        Trigger the handler
        </div>
    </body>
</html>
最佳回答

Always wrap your bind methods with the document ready function:

   <script>
   $(function () {

                $( #target ).submit(function() 
                {
                alert( Handler for .submit() called. );
               });
    });
    </script>

<>edit>/em>之所以有必要,是因为如果你在文件准备就绪之前试图对文件加以约束,那么光标的物还不存在很好的机会。 当然,你可以将这笔钱改成“原始目标”的美元(“提交”)职能(......),但这不是解决问题的良好想法。 如上文所述,使用现成手稿。

问题回答

主要问题是,你的遴选人正在选择目标标,而不是目标id的成分,从而改变:

 $( target ).submit(function() 

纽约总部

 $( #target ).submit(function() 

你们的第二个问题是,你们应该有围绕OMM准备活动总结的贵重法律。

您错了一张标志。

<script>
                    $( #target ).submit(function() 
                    {
                    alert( Handler for .submit() called. );
                   });
        </script>

你们需要tag子(#),供选择。

$( #target ).submit(function() 
...

Because when this code is executed there is no target yet. Use .ready(). Also it should be $( #target ) as id selectors should be prefixed with #.

$(function(){
    $( #target ).submit(function() 
    {
        alert( Handler for .submit() called. );
    });
}

<代码>#在选任人中缺失。

$( #target ).submit(function(){ });

Use it this way:

 <script>
           $(document).ready(function () {

               $( #target ).submit(function () {
                   alert( Handler for .submit() called. );
               });
           });
    </script>




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签