2013-05-28 52 views
-1

我有jQuery的崗位操作鏈接:從服務器如何把js鏈接?

$.post('my_url', { 
    'pid': pid, 
    'name': $('input#nametxt').val() 
}, function(data){ 
    $('#list').append(data); 
}); 

Respose是例如:

<li>My custom name <a href="javascript:add_another('23');">Add another</a></li> 

但這種動態添加的鏈接無法使用。如何做得好?

+1

什麼不起作用?你不能點擊鏈接或Javascript函數'add_another'沒有被調用? – Biketire

回答

1

你可以把它像這樣

返回下面的輸出從服務器端開始當前廣告。

<li>My custom name <a href="javascript:void(0);" propId="23">Add another</a></li> 

並執行以下操作上的頁面加載

$(function(){ 
    $("#list").on("click", "a", function() { 
    add_another($(this).attr('propId')); 
    }); 
}); 
+0

謝謝,這項工作非常完美! – Nips

-1

將其更改爲:

<a href="javascript:void(0);" onclick="javascript:add_another('23');">Add another</a></li> 
0

爲什麼不把

$("#list").on("click", "a", function() { 
    add_another($(this).attr('id')); 
}); 

和性反應的從服務器:

<li>My custom name <a id="23">Add another</a></li> 
0

能否請您與您的腳本文件檢查是在同一臺服務器上(某些情況下出現跨域問題)

謝謝, Dhiraj