解析PHP的基本文本输出
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!
更多相关文章
- 禁用焦点上的锚点()元素上的灰色边框
- 在jQuery中使用部分ID查找元素?(复制)
- 获取复选框的文本属性
- 使用数字作为javascript对象元素的名称
- 将JSON结果返回给ajax请求的MVC ErrorHandling属性仅适用于local
- 使用类似$(“。someClass”)的JQuery确定元素集合是否可见
- 创建一个未排序的数组,其中包含重复元素和唯一元素的总和
- jQuery在元素内部检测mousedown,然后在元素外部进行mouseup
- 如何在angularjs代码中单元测试jquery元素