2012-06-19 85 views

回答

2

你需要委派事件。因为您的按钮在页面加载后即被添加到DOM。动态,所以你需要像下面:

$('body').on('click', '.button', function() { 
    alert('TEST!'); //it doesnt work    
}); 

DEMO

+0

但是你看,我加载某些形式到我的用户界面对话框中点击链接(在后dom准备就绪,我想),我想通过ajax提交它 - 它会使用你的方法之一吗? – pawel

+0

@pawel yup,它会工作 – thecodeparadox

+0

谢谢你,节省了我很多的时间! :) – pawel

2

呼叫

$(".button").click(function() { 
      alert('aaa'); 

在对话框

$("#dialog").dialog({ 
     autoOpen: false, 
     title: "contact", 
     open: function() { 
      $(".button").click(function() { 
       alert('aaa'); 
      }); 
     } 
    }); 
2

开放的行动,我建议把的onclick在提交按钮

<input type='submit' name='submit' class='button' 
id='submit' value='Zapisz' onclick='dingDong()' /> 

http://jsfiddle.net/GexFz/1/