이 방법을 사용하여 텍스트를 찾아서 바꾸고 왜 작동하지 않는지 확신하지 못합니까? console.log를 사용하면 바꿀 내용이 올바르게 표시되지만 최종 결과가 작동하지 않습니다.jQuery가 텍스트를 바꾸지 못합니다.
의견이 있으십니까?
감사합니다.
이 방법을 사용하여 텍스트를 찾아서 바꾸고 왜 작동하지 않는지 확신하지 못합니까? console.log를 사용하면 바꿀 내용이 올바르게 표시되지만 최종 결과가 작동하지 않습니다.jQuery가 텍스트를 바꾸지 못합니다.
의견이 있으십니까?
감사합니다.
당신은
$(document).ready(function() {
var theContent = $(".transaction-results p").last();
console.log(theContent.html());
theContent.html(theContent.html().replace(/Total/, 'Total without shipping:'));
});
(function($) {
$(document).ready(function() {
var theContent = $(".transaction-results p").last();
console.log(theContent.html());
theContent.html(theContent.html().replace('Total:', 'Total without shipping:'));
});
})(jQuery);
은 일반 문자열과 같은 /Total:/
하지 'Total'
을 한 이유는 무엇입니까?
@David Thomas의 솔루션이 작동합니다. 그것은 온 대체하지 않습니다 -
그는 정규 표현식을 사용했기 때문에 문자열이 아닙니다. –
하려면 string.replace 문자열을 반환 검색도 theContent의 HTML로 다시 지정하는 문자열에 추가
:
이 당신이 참조하는 문자열 ...'theContent.html (theContent.html(). replace (/ Total : shipping : 'Total without shipping :')),' – Archer@diEcho 이것은 PHP가 아니며 정규 표현식을 인용 부호. – Barmar