jQuery拆分功能 [英] Jquery split function

查看:77
本文介绍了jQuery拆分功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有如下的ajax功能

I have a ajax function as below

<script type="text/javascript">
$(document).ready(function () {

var timer, delay =600000; //5 minutes counted in milliseconds.

timer = setInterval(function(){
    $.ajax({
  type: 'POST',
  url: 'http://localhost/cricruns-new/index.php/score-refresh/fetchdes/index/86/1',
  success: function(html){

    alert(html);
  }
});

},delay);

});
</script>

它输出以下

total:-370:-wickets:-4:-overs:-50.0:-striker:-Yusuf Pathan:-sruns:-8:-sballs:-10:-sfour:-0:-ssix:-0:-nonstriker:-Virat Kohli:-nsruns:-100:-nsballs:-83:-nsfours:-8:-nssix:-2

我想使用:-拆分结果,并且我必须为id为奇数的div分配偶数..

i want to split the result using :- and i have to assign even values to the div which has the id as the odd value..

推荐答案

尝试一下.它使用 split 函数,该函数是javascript,与jQuery无关.

Try this. It uses the split function which is a core part of javascript, nothing to do with jQuery.

var parts = html.split(":-"),
    i, l
;
for (i = 0, l = parts.length; i < l; i += 2) {
    $("#" + parts[i]).text(parts[i + 1]);
}

这篇关于jQuery拆分功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆