function batchSetImageWidth() {
var content = ueditor.getContent();
var parser=new DOMParser();
var doc=parser.parseFromString(content,'text/html');
var imgElements = doc.getElementsByTagName('img');
for (let imgElement of imgElements) {
//1.如果有style属性,去掉style属性中的width属性和height属性
if (imgElement.hasAttribute('style')) {
// 获取style属性的值
var styleValue = img.getAttribute('style');
// 使用正则表达式去掉width和height属性
var updatedStyleValue = styleValue.replace(/(width\s*:\s*\d+\s*px\s*;?|height\s*:\s*\d+\s*px\s*;?)/gi, '');
// 更新img标签的style属性
imgElement.setAttribute('style', updatedStyleValue);
}
//2.如果有height属性,去掉img中的height属性
if (imgElement.hasAttribute('height')) {
// 去掉height属性
imgElement.removeAttribute('height');
}
//3.设置img中的width属性
imgElement.setAttribute('width',newWidthValue)
}
//设置回去
var serializer = new XMLSerializer();
var updatedContent = serializer.serializeToString(doc);
ueditor.setContent(updatedContent);
}