Javascript Java脚本如何在J查询中动态生成的列表中触发事件 $(文档).ready(函数(){ $(“.AddTopHundWatchList”)。单击(函数(){ $.ajax({ 键入:“获取”, url:“/WatchListTopHund/”, 成功:功能(数据){ var raw_tag=“”; var add_new=“add new” var json_array=data.json_array; for(var json_count=0;json_count
我已经使用java scipt动态创建了一个列表,我想在正常HTML生成的列表中调用click event as go(单击事件)。这是我迄今为止尝试过的,但我无法触发一个事件。有人能帮我吗?尝试:Javascript Java脚本如何在J查询中动态生成的列表中触发事件 $(文档).ready(函数(){ $(“.AddTopHundWatchList”)。单击(函数(){ $.ajax({ 键入:“获取”, url:“/WatchListTopHund/”, 成功:功能(数据){ var raw_tag=“”; var add_new=“add new” var json_array=data.json_array; for(var json_count=0;json_count,javascript,html,jquery,javascript-events,Javascript,Html,Jquery,Javascript Events,我已经使用java scipt动态创建了一个列表,我想在正常HTML生成的列表中调用click event as go(单击事件)。这是我迄今为止尝试过的,但我无法触发一个事件。有人能帮我吗?尝试: $(document).ready(function() { $(".addtophundredwatchlist").click(function() { $.ajax({ type : "GET", url : "/watchlisttophu
$(document).ready(function() {
$(".addtophundredwatchlist").click(function() {
$.ajax({
type : "GET",
url : "/watchlisttophundred/",
success : function(data){
var raw_tag = "<ul>";
var add_new = "Add New"
var json_array = data.json_array;
for (var json_count = 0; json_count < json_array.length; json_count++)
{
var raw_string = "<li id='watchlistitem' class='watchlistitem'>" + "<input type='button' id='watchlistbutton' class='watchlistbutton' value='*'>" + json_array[json_count].watch_list_name + "</li>"
raw_tag = raw_tag + raw_string
}
raw_tag = raw_tag + "<li id='addnew' class='addnew'>" + add_new + "</li>"
raw_tag = raw_tag + "</ul>"
$(".listwatchlist").html(raw_tag)
//$(this).next().toggle();
//alert($(".tophundredwatchlist",$(this)).html());
//alert($(this).next().val())
$(".tophundredwatchlist").toggle();
}
});
});
$(".addnew").click(function() {
alert("Add New Clicked");
$(".addnew").html("<input class='newwatchlisttext' name='newwatchlisttext' type='text' autocomplete='off' id='newwatchlisttext'/>")
});
$(".watchlistitem").click(function() {
alert("Add New Clicked");
//$(".addnew").html("<input class='newwatchlisttext' name='newwatchlisttext' type='text' autocomplete='off' id='newwatchlisttext'/>")
});
尝试:
给您的
一个id:
$('.addnew').delegate('li', 'click', function ()
{
//add your code here
});
//OR
$('.addnew').live('click', function ()
{
//add your code here
});
var raw_tag=“”;
那么你的JS应该看起来像:
var raw_tag = "<ul id='my_list_id'>";
$(“#我的列表_id”)。在('click'、'li.watchlistitem',函数()上{
警报(“添加新单击”);
//$(“.addnew”).html(“”)
});
给你的一个id:
$('.addnew').delegate('li', 'click', function ()
{
//add your code here
});
//OR
$('.addnew').live('click', function ()
{
//add your code here
});
var raw_tag=“”;
那么你的JS应该看起来像:
var raw_tag = "<ul id='my_list_id'>";
$(“#我的列表_id”)。在('click'、'li.watchlistitem',函数()上{
警报(“添加新单击”);
//$(“.addnew”).html(“”)
});
您可以为列表添加id
$("#my_list_id").on('click', 'li.watchlistitem', function() {
alert("Add New Clicked");
//$(".addnew").html("<input class='newwatchlisttext' name='newwatchlisttext' type='text' autocomplete='off' id='newwatchlisttext'/>")
});
您可以为列表添加id
$("#my_list_id").on('click', 'li.watchlistitem', function() {
alert("Add New Clicked");
//$(".addnew").html("<input class='newwatchlisttext' name='newwatchlisttext' type='text' autocomplete='off' id='newwatchlisttext'/>")
});
+1on
是附加动态内容事件的首选方式+1on
是附加动态内容事件的首选方式