从Jquery成功结果中选择 [英] selecting from Jquery success result

查看:61
本文介绍了从Jquery成功结果中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

异步发布成功后,我正在尝试更新页面的一部分.

I'm trying to update a part of a page after the success of an asynchronous post.

所以我有

success: function (data, status, xhr) {
        var elementName = "#div" + gridName;
        var findResult = $(data).find(elementName);
        $(elementName).html($findResult);

现在,当我查看数据时,HTML看起来像这样:

Now when I view data the HTML looks like:

<div class="t-grid-header">
<div class="t-grid-header-wrap">
<table cellspacing="0">

但是当我从findResult检查HTML时,它看起来像:

but when I inspect the HTML from findResult it looks like:

<DIV class=t-grid-header>
<DIV class=t-grid-header-wrap>
<TABLE cellSpacing=0>

这不是好" HTML,所以我不能使用它.因此,我如何获得好的HTML. findResult.html()无法正常工作,因为调用为时已晚.转换已经发生.

This is not 'good' Html so I can't use it. So how do I get good HTML. findResult.html() doesn't work because the call is too late. The conversion has already happened.

我该如何进行?

推荐答案

我猜您在IE9之前使用的是IE的某个版本.在较旧版本的IE中提取innerHTML时,结果看上去与您输入的内容非常不同(包括大写,属性引用,属性顺序等),这是很常见的.这就是这些较旧版本的IE所做的.

I will guess that you are using some version of IE before IE9. It is quite common that when you fetch the innerHTML in older versions of IE, the result looks very different than what you put in (including capitalization, quoting of attributes, order of attributes, etc...). This is what these older versions of IE do.

对您来说幸运的是,任何在获取该innerHTML时创建该innerHTML的浏览器也将在您对其进行设置时接受该innerHTML,因此您不必担心.在非IE浏览器(或IE9)中尝试此操作,我认为您不会看到相同的东西.

Fortunately for you, any browser that creates that innerHTML when you fetch it, will also accept that innerHTML when you set it so you shouldn't need to worry. Try this in a non-IE browser (or in IE9) and I don't think you will see the same thing.

这篇关于从Jquery成功结果中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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