File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -247,12 +247,20 @@ export function solveWeChatImage() {
247247 const images = clipboardDiv . getElementsByTagName ( `img` )
248248
249249 Array . from ( images ) . forEach ( ( image ) => {
250- const width = image . getAttribute ( `width` ) !
251- const height = image . getAttribute ( `height` ) !
252- image . removeAttribute ( `width` )
253- image . removeAttribute ( `height` )
254- image . style . width = width
255- image . style . height = height
250+ const width = image . getAttribute ( `width` )
251+ const height = image . getAttribute ( `height` )
252+
253+ if ( width ) {
254+ image . removeAttribute ( `width` )
255+ // 如果是纯数字,添加 px 单位;否则保持原值
256+ image . style . width = / ^ \d + $ / . test ( width ) ? `${ width } px` : width
257+ }
258+
259+ if ( height ) {
260+ image . removeAttribute ( `height` )
261+ // 如果是纯数字,添加 px 单位;否则保持原值
262+ image . style . height = / ^ \d + $ / . test ( height ) ? `${ height } px` : height
263+ }
256264 } )
257265}
258266
You can’t perform that action at this time.
0 commit comments