2

该代码位于@ http://www.iluvtrees.org/,我们正在尝试删除冒号(:)...

jQuery('#events-calendar-list li a').text(this.text().replace(':', ''));

我正在远程执行此操作,并且能够使用此脚本获得一个更简单的字符串来工作。选择器中的难点,我们的html看起来是这样的……

...
<ul id="events-calendar-list">
<li id="events-calendar-list-630" title="
<strong>Title: </strong><b>#62 It's Little Things
</b><br />Check your fuel consumption and tire pressure to make sure your car is running as efficiently as possible.
<br /><strong>Start Time: </strong>12:00 am<br /><strong>End Time: </strong>12:00 am<br />">events=Object { mouseover=[1]}handle=function()
<a href="http://www.iluvtrees.org/">
<strong style="display: none;">Thu 3/14/2013</strong>
: //<- - - this is what we are trying to remove - - - -
<b>#62 It's Little Things</b>
<br>
</a>
...

我目前无权访问 PHP 文件以从那里删除。


还有第三个选项使用cookie.

参考 -动态生成内容的 GWT 国际化

在用户选择他的语言环境之前,请确保您为 cookie 设置了语言环境值或为您的 cookie 设置了默认值。在我们的例子中,用户在登录前选择一种语言(我在其中为用户设置 cookie 区域设置值)并在加载时将其读入 gwt 应用程序。

4

4 回答 4

3

您可以简单地删除锚内的文本节点:

$('a').contents().filter(function(node) {
  return this.nodeType === 3; // filter text nodes
}).remove();

演示

于 2013-03-15T03:49:48.920 回答
1

工作演示

好的,从您提供的链接中,我假设所有元素都遵循相同的格式。

所以使用这个:

// .replace('</strong>: <b>','</strong><b>'); fiddle with the HTML, you can't use .text() here

jQuery('#events-calendar-list li a').html(jQuery('#events-calendar-list li a').html().replace('</strong>: <b>','</strong><b>'));
于 2013-03-15T03:50:51.393 回答
1

如下所示。

jQuery('#events-calendar-list li a').text(jQuery('#events-calendar-list li a').text().replace(':', ''));

在许多编程语言中this (或 self)是一个关键字,可以在实例方法中使用,以引用当前正在执行的方法已被调用的对象。

于 2013-03-15T03:33:50.470 回答
0
<html>
        <head>
                <title>Test Website</title>
                <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
                <script>
                        $(document).ready(function() {
                                var x = $('a#test').text();
                                alert(x.replace(':', ''));
                        });
                </script>
        </head>
<body>

<ul id="events-calendar-list">
<li id="events-calendar-list-630" title="
<strong>Title: </strong><b>#62 It's Little Things
</b><br />Check your fuel consumption and tire pressure to make sure your car is running as efficiently as possible.
<br /><strong>Start Time: </strong>12:00 am<br /><strong>End Time: </strong>12:00 am<br />">events=Object { mouseover=[1]}handle=function()
<a id="test" href="http://www.iluvtrees.org/">
<strong style="display: none;">Thu 3/14/2013</strong>
: //<- - - this is what we are trying to remove - - - -
<b>#62 It's Little Things</b>
<br>
</a>


</body>
</html>
于 2013-03-15T03:44:01.303 回答