jQuery 针对点击按钮替换指定文字的事件?看似简单,求大神降临!
jQuery点击#__btn_544时判断如果有‘taskdone,pleasecheckit,thanks’文字内容,就替换成‘pleaseproceedwiththi...
jQuery 点击 #__btn_544 时判断如果有‘task done, please check it, thanks’文字内容,就替换成‘please proceed with this, thanks’如果没有就像下面一样:
// Auto Fill Comments When Proceed to Next Step
var comments = $('#gworkflow_explore_comments');
// [WB] New request
$('#__btn_544').click(function() {
if (comments.val() == '') comments.val('please proceed with this, thanks');
comments.val().indexOf('please proceed with this, thanks') != -1 ? comments.val(comments.val()) : comments.val(comments.val() + '\nplease proceed with this, thanks');
});
// [QA] QA review
$('#__btn_542').click(function() {
if (comments.val() == '') comments.val('task done, please check it, thanks');
comments.val().indexOf('task done, please check it, thanks') != -1 ? comments.val(comments.val()) : comments.val(comments.val() + '\ntask done, please check it, thanks');
}); 展开
// Auto Fill Comments When Proceed to Next Step
var comments = $('#gworkflow_explore_comments');
// [WB] New request
$('#__btn_544').click(function() {
if (comments.val() == '') comments.val('please proceed with this, thanks');
comments.val().indexOf('please proceed with this, thanks') != -1 ? comments.val(comments.val()) : comments.val(comments.val() + '\nplease proceed with this, thanks');
});
// [QA] QA review
$('#__btn_542').click(function() {
if (comments.val() == '') comments.val('task done, please check it, thanks');
comments.val().indexOf('task done, please check it, thanks') != -1 ? comments.val(comments.val()) : comments.val(comments.val() + '\ntask done, please check it, thanks');
}); 展开
1个回答
展开全部
$('#__btn_544').click(function() {
var _txt = 'task done, please check it, thanks',
_dft_txt = 'please proceed with this, thanks',
_val = $.trim(comments.val());
if (!_val || _val.indexOf(_txt)>=0) comments.val(_dft_txt);
else comments.val(_val.indexOf(_dft_txt)>=0?_val:(_val + "\n" + _dft_txt));
});
更多追问追答
追问
你好,首先谢谢你的回答,
但是还没有解决我的问题:
上面的代码是只要有'task done, please check it, thanks'这句话点击按钮就会把文本框里面的文字全都替换成了'please proceed with this, thanks',
但是我想要的效果是只替换'task done, please check it, thanks'这一句话,其他的文字还保留...
请不吝赐教!
追答
$('#__btn_544').click(function() {
var _txt = 'task done, please check it, thanks',
_dft_txt = 'please proceed with this, thanks',
_val = $.trim(comments.val()),
_regex = new RegExp(_txt, 'g');
if (!_val || _val.indexOf(_txt)>=0) comments.val(_val.replace(_regex, _dft_txt));
else comments.val(_val.indexOf(_dft_txt)>=0?_val:(_val + "\n" + _dft_txt));
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询