开发者

Not performing yes click event

So what's supposed to happen is when the user clicks the yes answer its supposed to get the id of the img and then perform its tasks but I don't know if I should be putting the id onto the link instead of the image but the main part of the question is its not doing the steps of the yes click function.

I was using the same plugin from this page. http://webstuffshare.com/demo/jConfirmAction/index.html And using the plugin with the default usage

<td> 
<a class="ask" href="#"> 
<img id="2" class="delete" border="0" title=开发者_StackOverflow"" alt="" src="images/trash.png"> 
 </a>
 <div class="question" style="opacity: 1;">
  Are You Sure ?
   <br>
  <span class="yes">Yes</span>
  <span class="cancel">Cancel</span>
 </div>
</td>

$('.ask').jConfirmAction();

$('.yes').bind('click', function(){
    var userID = $(this).parent.attr('id'); 
    var dataString = 'userID=' + userID + '&deleteuser=True'; 
    $.ajax({ 
        type: "POST", 
        url: "processes/template.php", 
        data: dataString, 
    });
    $(this).parents("tr").eq(0).hide();   
}); 


You don't have anything with a class of yes to bind that click to.

EDIT: (post addition of generated code)

try putting your id in your <div class="question" style="opacity: 1;"> if you can't do add it to your td and change to var userID = $(this).parents('td').attr('id');


Ok, so what you should be seeing in the client (the web browser) is this:

<td>
    <a href="#" class="ask">
        <img src="images/trash.png" class="delete" alt="" title="" border="0" id="some value" />
    </a>
</td>

So, you gave your image an id, yet your jQuery selector is an attempt to bind a click event to the hyperlink, with a function that tries to parse the id of the table cell. As someone else mentioned, the selector selects nothing because there is nothing that matches it.

Do you see where I'm going with this?

Edit:

To set the click event on the image:

$(".delete").click(function(e){ 
    var id = e.target.id; 

    // ... the rest here
});

To set it on the hyperlink:

$(".ask").click(function(e){ 
    e.preventDefault();

    var id = $(this).("img").attr("id"); 

    // ... the rest here
});

Edit 2:

If your goal is to provide a confirmation prompt, I'd follow the K.I.S.S. principle; use the JavaScript confirmation prompt when the delete link is clicked:

$(".ask").click(function(e){ 
    e.preventDefault();

    if(confirm("Are you sure?")){
        var id = $(this).("img").attr("id"); 

        // ... the rest here
    }
});


Try using alert("Some message"); just before your call to the bind. Place another as the first instruction of your function(). to see if both of these pieces of code are even being reached.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜