English 中文(简体)
不发射的弹que功能
原标题:jquery function not firing at all
  • 时间:2011-11-16 13:06:05
  •  标签:
  • jquery

Real Dumb question. 我说,到现在,我本来会直截了当,但我显然没有东西。 我希望,一旦页数上载,我就能够控制变数的价值,并根据这一价值,使纽芬兰出现或消失。 但是,我所写的职能从未被召唤。 我将这一职能放在Load(文件)和(文件)美元之内。 随时随叫.。 我怎么能让这一职能火上?

 $(document).ready(function () {
        debugger;        
        (function () {           
        debugger;
        var $b =  <%=toggle %> ;
        var buttonTog = $("#test1");
        var buttonTog1 = $("#Submit1");
        if($b=="1")
        {
            debugger;
            buttonTog1.css({
                display:  block 
            })
            buttonTog.css({
                display:  none 
            });
        }
        else if($b=="0")
        {
            debugger;
            buttonTog1.css({
                display:  none 
            })
            buttonTog.css({
                display:  block 
            });
           }            
       });
       ...
    });

如你所知,我在那里有多次夸张的言辞,那就没有打过......。 当我打了美元(文件)。 我已经准备好,而且我参加了第一次夸张的发言,这只是 t弄下一个功能吗? 我看不到吗? 这是正确的吗? 您能否在校读(功能)内称职? 显然需要做一些研究。

最佳回答

你规定了匿名职能,但你从未称呼。 如何使匿名职能自动化:

$(document).ready(function () {
    (function() {
        var buttonTog = $("#test1");
        var buttonTog1 = $("#Submit1");
        ...
    })(); // <!-- notice the (); at the end
});

尽管如此,我几乎看不出在<编码>文件.ready内使用这一匿名自动发泄功能的有用性,而这种功能本身是匿名的。 事情开始到底是私人的:

你可以简单地在其中写成法典:

$(document).ready(function () {
    var buttonTog = $("#test1");
    var buttonTog1 = $("#Submit1");
    ...
});

我怀疑你可能缺乏关于<代码>(文件)的某些重要概念。 <现成/编码>功能及其辛醇。 http://api.jquery.com/ready/>。 文件的例子更多。

问题回答

仅删除<代码>(功能(){和>);

You ve defined your function, but you ve never called it. Call it.

function doSomething () {           
        debugger;
        var $b =  <%=toggle %> ;
        var buttonTog = $("#test1");
        var buttonTog1 = $("#Submit1");
        if($b=="1")
        {
            debugger;
            buttonTog1.css({
                display:  block 
            })
            buttonTog.css({
                display:  none 
            });
        }
        else if($b=="0")
        {
            debugger;
            buttonTog1.css({
                display:  none 
            })
            buttonTog.css({
                display:  block 
            });
           }            
       });

之后

$(function(){
     doSomething(); // here, you ve executed your function
});

这将完全发挥作用......

http://jsfiddle.net/GfjHd/“rel=“nofollow” http://jsfiddle.net/GfjHd/。

传真

<input type="button" value="One" id="test1" />
<input type="button" value="Two" id="Submit1" />

Java

$(document).ready(function () {      
        var $b =  1 ;
        var buttonTog = $("#test1");
        var buttonTog1 = $("#Submit1");
        if($b=="1")
        {
            //debugger;
            buttonTog1.css({display:  block });
            buttonTog.css({display:  none });
        }
        else if($b=="0")
        {
           // debugger;
            buttonTog1.css({display:  none })
            buttonTog.css({display:  block });
         }            
    });




相关问题
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: &...

热门标签