主页 论坛标题的图片
今天感觉做的很简单,就是如果我们在后端得到的数据,需要找出 "<img>"标签。并打包
js 里边字符串检索 能力indexOf 与 截取 subString(x,y)
//我们在混乱数据的返回中,只要截取 <img>特征。
最开始我考虑的是整段<img>的截取,这样虽然也是简单,但是样式Style是无法更新。
所以最好截取<img> 中的src,然后document.createElement(img)去自己更改样式。
<script>
function ab(){
var textScript=" <img src=\"img/202253221937.png\" style=\"max-width: 60%\" title=\"图片1\" />\n" +
" <img src=\"img/20220406132558.png\" style=\"max-width: 60%\" title=\"图片2\" />\n" +
" <img src=\"img/20220412022933.png\" style=\"max-width: 60%\" title=\"图片3\" />\n" +
" <img src=\"img/20220412023025.png\" style=\"max-width: 60%\" title=\"图片4\" />\n" +
" <img src=\"img/20220412023633.png\" style=\"max-width: 60%\" title=\"图片5\" />\n" +
" <img src=\"img/20220412024324.png\" style=\"max-width: 60%\" title=\"图片6\" />"
var j=0;
var divTextScript="";
var div1=document.getElementById("picture");
for (var i=0;i<6;i++){
var head= textScript.indexOf("src",j)+5
var foot= textScript.indexOf(".",j)+4;
// alert(head+" "+foot+" "+textScript.substring(head,foot));
var divTextScript1=textScript.substring(head,foot);
j=foot;
alert(divTextScript1)
// divTextScript=divTextScript+divTextScript1;
// div1.innerHTML=divTextScript;
}
}
</script>