Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
291 views
in Technique[技术] by (71.8m points)

jquery - Finding and displaying image src attributes

I have a problem and an try to find in one week. I need help :(

I have a script work with :

<script type="text/javascript">
var list_images = 'image1.jpg|image2.jpg|image3.jpg|image4.jpg|image5.jpg|image6.jpg|image7.jpg';
var images = list_images.split('|');
</script>

but know in blogger always give more tab in my script

<script type="text/javascript">
var list_images = '

<div></div>
<a herf="anything"><img src="image1.jpg"><a/>
<a herf="anything"><img src="image2.jpg"><a/>
<a herf="anything"><img src="image3.jpg"><a/>
<a herf="anything"><img src="image4.jpg"><a/>
<a herf="anything"><img src="image5.jpg"><a/>
<li><img src="image6.jpg"></li>
<li><img src="image7.jpg"></li>
<br/>

';
var images = list_images.split('|');
</script>

I want remove all tabd and convernt them like

var list_images = 'image1.jpg|image2.jpg|image3.jpg|image4.jpg|image5.jpg|image6.jpg|image7.jpg';
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The Blogger editor is unfortunately not designed well to handle code blocks.

By default, it adds a <br/> tag to the end of every line causing your well formatted script to fail.

The only workaround I've seen so far isn't pretty.

<script type="text/javascript">/*
  */var list_images = /*
  */'image1.jpg|image2.jpg|image3.jpg|image4.jpg|image5.jpg|image6.jpg|image7.jpg';/*
  */var images = list_images.split('|');/*
*/</script>

Essentially everything after then end of a line up to the begining of the next line is forced to be a comment so that when Blogger injects the <br/> tags they are ignored by the browser.

Result after Blogger injects the BRs:

<script type="text/javascript">/*<br/>
  */var list_images = /*<br/>
  */'image1.jpg|image2.jpg|image3.jpg|image4.jpg|image5.jpg|image6.jpg|image7.jpg';/*<br/>
  */var images = list_images.split('|');/*<br/>
*/</script><br/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...