【发布时间】:2010-11-18 11:10:14
【问题描述】:
我正在尝试找到所有 <h2> 标记并将它们拆分并与它们周围的 <a href=''></a> 一起加入它们。我很接近但卡住了。
<script type="application/javascript">
$(document).ready(function() {
// finds all h2's within wrapper div grabs the text splits at ? and applies a links around each one
var al = $('#wrapper').find('h2').text().split("?").join("?</a><br /> <a href='#'>");
// Add all the split h2's from the variable above al to a div called .text
$('.text').html('<ul>' + al + '</ul>');
});
</script>
这是我的 alert(al) 输出:
Appropriate Media – Why radio?</a><br /> <a href='#'>Can someone come and speak at my church?</a><br /> <a href='#'>Do you distribute radios?</a><br /> <a href='#'>Do you partner with other organisations?</a><br /> <a href='#'>How is Feba funded?</a><br /> <a href='#'>What are your programmes about?</a><br /> <a href='#'>What denomination does Feba belong to?</a><br /> <a href='#'>What happened to the Chrysolite?</a><br /> <a href='#'>What is airtime?</a><br /> <a href='#'>What is Feba's Statement of Faith?</a><br /> <a href='#'>Where are the programmes made?</a><br /> <a href='#'>Where can I find out about the languages & countries you broadcast in?</a><br /> <a href='#'>Where does the name Feba come from?</a><br /> <a href='#'>Who do you broadcast to?</a><br /> <a href='#'>Why do you broadcast on short wave?</a><br /> <a href='#'>
好的,目前我可以在? 拆分它们,因为每个问题都以? 结尾,但我的问题是这错过了第一个问题。
所以我的解决方案是在<h2> 标签处拆分它们,这是可能的还是我尝试了很多更好的选择?
【问题讨论】: