English 中文(简体)
如果检查,则用检查箱套套套套套回,就会获得任何回报?
原标题:jquery append with checkbox, if checked, it wont return anything?

I have dynamically generated a list of wine types from the database using AJAx and PHP here is the function

function wineTypeHandler(data){
            var Type = data.Type;
            var countType = data.countType;
            for(var i = 0; i < countType; i++){

                $("#selectType").append(

                $("<input />").attr({
                  type:  checkbox ,
                    name:  Type ,
                    class:  wineTypeCheck ,
                     value: Type[i]
                  }), Type[i] + "<br />"
            );
            }   
        }

你们可以看到,我“向某些人申请”结果,这整件事情都做了罚款,因此,我的唯一问题是,我想要根据从这份清单中核实的内容更新另一个清单时,它会积极回答任何事情! 当我尝试这种方式时,还有许多其他方式

$(document).ready(function(){

$( :checkbox ).click(function(){
alert( started );

    // other code
        return true;

});

});

It doesnt alert anything!! Can anybody help me with this problem.

事先感谢你。

最佳回答

.click(>>> 依附于建立OMS时存在的内容。 您的内容正在动态生成,因此,.click()没有实际应用。

You should use .live() to target dynamically generated elements, as it attaches itself to any element that is created after the DOM is initially loaded. I also suggest using the change event instead of a click:

$( :checkbox ).live( change , function(){
  // No need to return true;
});
问题回答

This is because you are assigning the click function once your page has loaded but before your checkboxes have been dynamically created.
Depending on what version of jQuery you are using you can use the on() (for jQuery version 1.7 or above), delegate() (for older versions of jquery) or live() (simple but inefficient) functions to register an event to dynamically created elements.

公正的审判

$( :checkbox ).live( change , function(){

});

在将点子添加到OMS之后,你需要将点击事件捆绑起来。 这对贾瓦文发展来说是一个普遍的问题。 d 我建议设立一个职能,确定约束性活动,并在您的传讯(以及文件)之后召集。

Edit: I see a lot of recommendations for jQuery.live() It s important to note that the live() method of jQuery is deprecated and should not be used.

这项活动只与现有内容有关。 你们需要使用live

$( :checkbox ).live("click", function(){
    alert( started );
});

EDIT:

http://api.jquery.com/live/rel=“nofollow”>.live()方法被折旧。 利用.on()附属活动处理器。 较老的 j类使用者应比.live()。

jQuery 1.4.3+ use delegate

$(#selectType).delegate( :checkbox , "click", function(){
    alert( started );
});

jQuery 1.7+ use on

$(#selectType).on("click",  :checkbox , function(){
    alert( started );
});




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签