使用jquery将解析的文本转换为整数 [英] Converting a parsed text to integer with jquery

查看:129
本文介绍了使用jquery将解析的文本转换为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在解析一个XML文件,其中一个字段是一个整数,用于确定对象的大小:

  $( xml).find('Boxes')。each(function(){
var top = $ box.find('top')。text();
}


$ b

然后用HTML显示:

  var html ='< div class =boxstyle = top:'+ top +'px;< / div>'; 

我想给 top 添加一个常数300,我试过了:

  var html ='< div class =boxstyle =text-align:left; top:'+(parseInt(top)+300).text )+'px;< / div>'; 

但这个显示不正确,正确的方法来做到这一点?

解决方案

您使用的HTML无效。 code>< 与一个> ,并且您不会结束属性的引号。 eed to do:

  var html ='< div class =boxstyle = top:'+ top +'px ;> < / DIV>; 

或者添加一个常数,只需执行以下操作(不包含)。 text()> ):

  var html ='< div class =boxstyle =text-align:left; top:'+(parseInt(top)+300)+'px;>< / div>'; 


I am currently parsing a XML file and one field is an integer that determine the size of the object:

 $(xml).find('Boxes').each(function(){
  var top = $box.find('top').text();
  }

then to display it with HTML:

  var html = '<div class="box" style= top:'+ top +'px; </div>';

I want to add a constant number, 300, to top, I tried:

var html = '<div class="box" style="text-align:left; top:'+(parseInt(top)+300).text()+'px; </div>';

But this did not display correctly, is this the right way to do this?

解决方案

The HTML you're using is invalid. You're not closing your opening tag's < with a >, and you're not ending your attribute's quotes. To fix this, you'll need to do:

var html = '<div class="box" style= top:'+ top +'px;"> </div>';

or to add a constant number, just do the following (without the .text(), and with the ">):

var html = '<div class="box" style="text-align:left; top:'+(parseInt(top)+300)+'px;"> </div>';

这篇关于使用jquery将解析的文本转换为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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