【发布时间】:2013-11-19 13:02:57
【问题描述】:
我已经创建了这样的 jquery 选项卡:
$(function() {
$( "#tabContainer" ).tabs();
});
在其中添加了一些 href 链接:
$(document).ready(function(){
$("#tabContainer ul").append("<a href=# id='executePayLoad' class = 'buttonsExeSave'>Execute</a>");
$("#tabContainer ul").append("<a href=# id='inputPayLoadSave' class = 'buttonsExeSave'>DownloadRequest</a>");
$("#tabContainer ul").append("<a href=# id='expand' class = 'buttonsExeSave'>Expand</a>");
$("#tabContainer ul").append("<a href=# id='collapse' class = 'buttonsExeSave'>Collapse</a>");
单击“executePayLoad”链接后,我想将新的 href 链接动态附加到现有选项卡之一,如下所示:
$("#executePayLoad").click(function(){
if($('#outputPayLoadSave').length == 0)
$("#tabContainer ul").append("<a href=# id='outputPayLoadSave' class = 'buttonsExeSave'>DownloadResponse</a>");
.
.
.
.
});
点击“outputPayLoadSave”链接后,我想触发类似这样的事件:
$("#outputPayLoadSave").click(function(){
alert("inside");
GLR.messenger.show({msg:"Generating file...", mode:"loading"});
var xmlStr = xmlView.getXmlAsString();
$('#hidden_form > input[name=xml_string]').val(xmlStr);
$('#hidden_form > input[name=adapterName]').val(adapterValue);
$('#hidden_form > input[name=mode]').val("response");
$('#hidden_form').attr('action','xmlTreeView/Save.do');
$('#hidden_form').submit();
GLR.messenger.inform({msg:"Done.", mode:"success"});
});
但是当我单击“outputPayLoadSave”链接时,上面写的事件没有发生,即使控件没有进入该事件函数。有人可以帮帮我吗?
【问题讨论】:
-
当一组标记被动态添加到 DOM 中时,您应该使用委托函数。例如:live()(现已弃用)、.on()
http://api.jquery.com/on/
标签: javascript jquery