【问题标题】:Jquery taconite selector with character that needs to be escaped带有需要转义的字符的 Jquery taconite 选择器
【发布时间】:2009-10-06 00:28:51
【问题描述】:

我正在使用 jquery taconite 插件发出 ajax 请求,该请求将替换我页面中的某个元素,但是该元素的 id 类似于“email.subject”..

如果我选择'$("email\\.subject")',我可以选择它,但是当我尝试像这样使用 taconite 插件时:

<taconite>
    <replaceWith select="#email\\.subject">
        JUCA
    </replaceWith>
</taconite>

插件日志说:

[taconite] No matching targets for selector: #email\\.subject

我怎样才能做到这一点?

【问题讨论】:

  • 我通过用一个跨度包围有问题的标签使其工作,该跨度具有一个没有需要转义的字符的 id 属性......我替换它......我仍然想要知道如何让它正常工作,没有其他人遇到过这个问题吗?

标签: javascript jquery jquery-plugins escaping


【解决方案1】:

好的,这就是我所做的。但它对我不起作用。 (我没有浏览整个来源)。但它会为您指明正确的方向。

问题确实是在 jquery.taconite.js 文件中,大约第 152 行(如果您正在查看最新版本!)您可以看到:

var q = cmdNode.getAttribute('select');
var jq = $(q);

如果我在上述语句中添加警报以找出 jq 的值,它会显示:[Object object]。但只要它不包含 .

问题在于 taconite 的作者没有从“select”属性值中检查.。当我尝试将其隔离在一个简单的 js 文件中时,以下代码对我有用。但是当我在 jquery.taconite.js 文件中使用它时它不起作用。需要更多调整吗?

var x = cmdNode.getAttribute('select');
alert(x); //Shows what you have entered in <replaceWith select="#email.subject"> i.e "#email.subject"
var q = x.replace(/\./g, "\\\\\."); //Searches for a . in the string and escapes it! So now it becomes: "#email\\.subject"
alert(q) //Alerts #email\\.subject ... Great! Works fine till this point!
var jq = $(q);
alert(jq[0]); //Says "undefined"!!!! This is where i got stuck! Why does it say undefined??

【讨论】:

    猜你喜欢
    • 2011-02-16
    • 2011-03-20
    • 1970-01-01
    • 2011-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-28
    • 2020-07-21
    相关资源
    最近更新 更多