关于Ajax输出onclick事件 [英] onclick event on Ajax output

查看:685
本文介绍了关于Ajax输出onclick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我使用Ajax来获得一个SELECT标签。我的意思是,如果我点击一个按钮,它会生成HTML里面一个选择标记,我有选择的不同的选择不同的输出。

Hi i am using Ajax to get a SELECT tag. I mean, if i click on a button it will generate a SELECT tag inside HTML, i have different outputs for different options of select.

我需要的选择标记的onclick事件,我尝试使用JQuery

I need an onclick event on that SELECT tag, i tried using JQuery

$('#id').click(function() {
  alert('test');
});

它不工作。任何人可以帮助,请

Its not working. Can anybody help, please

推荐答案

由于选择标记的事件被设置后动态添加到HTML的,该事件没有设置在选择标签。

Because the select tag is dynamically added to the HTML after the event was set, the event is not set on the select tag.

有一个简单的解决方案是使用生活()这里:

A simple solution is to use live() here:

$('#id').live('click', function() {
  alert('test');
});

这篇关于关于Ajax输出onclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆