Last active
June 2, 2019 04:08
-
-
Save guerbai/9025758cfb2e34917d646a1185d05274 to your computer and use it in GitHub Desktop.
使用jquery替换chiild
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.prototype.replaceChildText = function (text) { | |
let textNodes = this.contents().filter(function() { | |
return this.nodeType === 3; | |
}); | |
textNodes.each(function() { | |
if (this.nodeValue.trim() !== '') { | |
this.nodeValue = text | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment