gpt4 book ai didi

javascript: string.replace 不起作用

转载 作者:搜寻专家 更新时间:2023-11-01 04:08:55 26 4
gpt4 key购买 nike

<分区>

我在替换 javascript/jquery 中的字符串时遇到了一点问题。首先是代码:

HTML:

<fieldset>
<legend>Contact persons</legend>
<div id="cm_contactPersons">
<fieldset id="cm_%email%">
<legend><span class="glyphicon glyphicon-circle-arrow-right"></span> %email%</legend>
<div class="form-group">
<label for="cm_%email_inputFirstname" class="col-sm-2 control-label">Firstname</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="cm_%email%_inputFirstname" value="%firstname%" placeholder="" required>
</div>
</div>
<div class="form-group">
<label for="cm_%email%_inputLastname" class="col-sm-2 control-label">Lastname</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="cm_%email%_inputLastname" value="%lastname%" placeholder="i. e. Max" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Actions</label>
<div class="col-sm-10">
<button type="button" class="btn btn-warning">Create new password</button>
<button type="button" class="btn btn-danger">Delete contact person</button>
</div>
</div>
</fieldset>
</div>
</fieldset>

Javascript:

$(document).ready(function() {
$('#cm_customerList').btsListFilter('#cm_customerSearchInput');
var editingArea = $('#cm_editingArea');
var contactPersons = $('#cm_contactPersons');
var contactPersonsTpl = contactPersons.html();
var alertArea = $('#cm_alertArea');

$('#cm_customerList > a').each(function() {
$(this).click(function(e) {
e.preventDefault();
$('#cm_customerList>a.active').removeClass('active');
$(this).addClass('active', 400);
$('html').animate({
scrollTop: 0
});
alertArea.fadeOut(400, function() {
alertArea.empty();
});
$.ajax({
type: 'GET',
url: 'index.php?' + $(this).attr('data-ajaxUrl'),
success: function(data) {
res = $.parseJSON(data);
editingArea.fadeOut(400, function() {
$('#cm_inputName').val(res.name);
$('#cm_inputStreet').val(res.street);
$('#cm_inputPostalcode').val(res.postalcode);
$('#cm_inputCity').val(res.city);
$('#cm_inputCountry option[value="' + res.country + '"]').prop('selected', true);
$('#cm_inputCountry').select2({
width: '100%'
});
$('#cm_inputTutors option:selected').prop('selected', false);
$.each(res.tutors, function(key, tutor) {
$('#cm_inputTutors option[value="' + tutor.username + '"]').prop('selected', true);
});
$('#cm_inputTutors').select2({
width: '100%'
});
contactPersons.empty();
$.each(res.contactpeople, function(key, contactPerson) {
contactPersons.append(contactPersonsTpl.replace('%email%', contactPerson));
});
editingArea.fadeIn();
});
},
error: function(xhr, ajaxOptions, thrownError) {
//error handler
}
});
});
});
});

带有“contactPersons.append(contactPersonsTpl.replace('%email%', contactPerson));”的部分替换根本不起作用。我尝试了所有各种类型的调试(日志、更改 substr 等)。没有机会。

但是如果我在 Firefox 控制台中写入“$('#cm_contactPersons').html().replace('%email%', 'test@blubb.at');”,有用。

我做错了什么?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com