我有jquery函数在MarkUp中传递Id参数。它工作正常,当我克隆函数时,它返回相同的Id。我希望它返回不同的ID ...我该如何获得不同的id参数?
这就是函数:
var generateMarkup = function(statusid, emailid) {
return '<div class = "divAddId" style="float:left;"><div id="wfEmailStatus' + statusid + "_" + emailid + 'Header">' +
'<input type="checkbox" name="wfEmailStatus' + ($('#workflowModalTabStatus' + statusid + "_" + emailid).length + 1) + 'Conditional" class="typ3 paleText" id="wfEmailStatus' + ($('#workflowModalTabStatus' + statusid + "_" + emailid).length + 1) + 'Conditional" value="Y" disabled="disabled" />' +
'<label for="wfEmailStatus' + ($('#workflowModalTabStatus' + statusid + "_" + emailid).length + 1) + 'Conditional" class="typ2 noTxtSelect1 paleText"> Delivery Conditional On Field </label>' +
'<input type="text" name="wfEmailStatus' + ($('#workflowModalTabStatus' + statusid + "_" + emailid).length + 1) + 'ConditionalFields" class="typ1 shad2 paleText" id="wfEmailStatus' + ($('#workflowModalTabStatus' + statusid + "_" + emailid).length + 1) + 'ConditionalFields" ' +
'value="" disabled="disabled" style="width:310px" />' +
'<input value = "Remove Field" type="button" class="smallbutt3" id="workflowEmailDeliveryStatus' + ($('#workflowModalTabStatus' + statusid + "_" + emailid).length + 1) + 'Remove" style="float:middle" disabled="disabled"></button></div></div>';
};
这是我的点击事件:
$('.smallbutt2').click(function() {
$parent = $(this).parent();
$rows =$parent.find('.divAddId');
var $newItem = $(generateMarkup(statusid, emailid));
$last = $rows.last();
$newItem.insertAfter($last);
var $break = $("<br />");
var $button = $newItem.find('.smallbutt3').first();
$button.click(function() {
$newItem.hide();
$newItem.remove();
$break.remove();
});
$button.fadeIn();
});
答案 0 :(得分:0)
var statusid = 1; // Initialize statusid
$('.smallbutt2').click(function() {
$parent = $(this).parent();
$rows =$parent.find('.divAddId');
var $newItem = $(generateMarkup(statusid, emailid));
statusid++; // Increment it after generating a new item
$last = $rows.last();
$newItem.insertAfter($last);
var $break = $("<br />");
var $button = $newItem.find('.smallbutt3').first();
$button.click(function() {
$newItem.hide();
$newItem.remove();
$break.remove();
});
$button.fadeIn();
});