English 中文(简体)
如何为动态生成的纽特确定点活动
原标题:how to set the click event for dynamic generated button
  • 时间:2012-04-09 07:14:47
  •  标签:
  • jquery

I am new to jquery. I wanted to generated a set of image button so i have done like this

  <script type="text/javascript">
$(document).ready(function(){
     $.support.cors = true;  
    if ($( #ulTask li ).length == 0)
    {
        $.ajax({
            type: "POST",
            url: "http://diana/TaskManagerWebService/TaskManagerService.asmx/SelectAllTasks",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: OnSuccess,
            error: OnError
        });
        function OnSuccess(TaskData){        
            var TaskDataObj = jQuery.parseJSON(TaskData.d);                
            $.each(TaskDataObj, function (i, v) {
               var TaskTypeUrl = getTaskTypeImageURL(TaskDataObj[i].TaskType), TaskId = parseInt(TaskDataObj[i].TaskId);
              $("#ulTask").append( <li id="liTask +TaskDataObj[i].TaskId+ "><div id="divTask +TaskDataObj[i].TaskId+ "><img id="imgCollapse +TaskDataObj[i].TaskId+ " alt="  + TaskDataObj[i].TaskId +  " src="Images/story_collapsed1.png" onclick="javascript:FillTaskDetails( +TaskDataObj[i].TaskId+ );"/>  + TaskDataObj[i].TaskName +  </div></li> );
            });
        }
        function OnError(request, status, error){                
            alert(request.statusText);
        }
    }
});
</script>

用于一对冲束的图像,有点击。

onclick="javascript:FillTaskDetails( +TaskDataObj[i].TaskId+ );"

我想在问候中指定这一点击事件,像对待囚犯一样。

$("#imageId").click(function(){
});

如何实现这一“理想”, 实际上,这种形象是文字和动态价值的结合。

<img id="imgCollapse +TaskDataObj[i].TaskId+ ".......

预 收

最佳回答

制作这些图像,以独特的类别名称

<img class="imgCollapse" id="imgCollapse +TaskDataObj[i].TaskId+ ".......

然后,将现场点击事件捆绑在一起。

$(".imgCollapse").live("click",function(event){
    event.preventDefault();
    taskID = $(this).attr( id ).replace( imgCollapse ,  );
    //console.log(taskID);
    FillTaskDetails(taskID);
 });
问题回答

审判时间

$("#imageId").live("click",function(){
    // Code is here ...
});




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