var req = function () {
    $.ajax({
       url: "out.php",
       cache: false,
       success: function(html) {
          $("#stuff").empty().append(html);
       },
       complete: function() {
          req();
       }
    });
};

req();

This snippet above gets the output in the following format: 0,0

上面的代码片段以下列格式获取输出:0,0

How can I parse that and have one number placed in the CSS selector top and the other in left?

我如何解析它并将一个数字放在CSS选择器顶部而另一个放在左边?

2 个解决方案

#1


Well, if I understood your PHP output it is something like x,y and you need x to be the CSS attribute top and y the CSS attribute left of an element. In my example, I will call the element which will hold these attributes with the id elem.

好吧,如果我理解你的PHP输出它就像x,y,你需要x作为CSS属性top和y左边的CSS属性。在我的例子中,我将使用id元素调用将保存这些属性的元素。

So here it goes:

所以这里:

var css_attr = req.split(",");
$('#elem').css('top', css_attr[0]).css('left', css_attr[1]);

If you'd like to do it just in success of AJAX call just change var css_attr to var css_attr = html.split(","); and the rest stays the same.

如果您想在AJAX调用成功的情况下执行此操作,只需将var css_attr更改为var css_attr = html.split(“,”);其余的保持不变。

That should be all. The split() function is pretty much equal to PHP's explode().

这应该是全部。 split()函数几乎等于PHP的explode()。

Enjoy!

更多相关文章

  1. 禁用焦点上的锚点()元素上的灰色边框
  2. 在jQuery中使用部分ID查找元素?(复制)
  3. 获取复选框的文本属性
  4. 使用数字作为javascript对象元素的名称
  5. 将JSON结果返回给ajax请求的MVC ErrorHandling属性仅适用于local
  6. 使用类似$(“。someClass”)的JQuery确定元素集合是否可见
  7. 创建一个未排序的数组,其中包含重复元素和唯一元素的总和
  8. jQuery在元素内部检测mousedown,然后在元素外部进行mouseup
  9. 如何在angularjs代码中单元测试jquery元素

随机推荐

  1. linux虚拟机空间不足解决
  2. Linux---more命令学习
  3. 拆分gzip压缩日志文件而不将未压缩的拆分
  4. 安装Linux系统的磁盘分区
  5. linux中安装fcitx输入法
  6. Linux 环境变量与文件查找
  7. 学习笔记: shell 中的 set -e , set +e 用
  8. linux 服务器间文件传输
  9. Zabbix - LINUX下CPU,硬盘,流量,内存监控
  10. 读书笔记-Linux C 编程从基础到实践-第一