replace multiple <br> tags with javascript

This question already has an answer here: How to replace all occurrences of a string in JavaScript? 41 answers You have specified that it's in document.body , so in the DOM. Then you can (and you should) use DOM methods: var siblingBrs = [].slice.call( document.querySelectorAll('br + br') ); siblingBrs.forEach( function( br ){ br.parentNode.removeChild( br ); }); http://jsfiddle.n

用javascript替换多个<br>标记

这个问题在这里已经有了答案: 如何在JavaScript中替换所有出现的字符串? 41个答案 你已经指定它在document.body ,所以在DOM中。 那么你可以(你应该)使用DOM方法: var siblingBrs = [].slice.call( document.querySelectorAll('br + br') ); siblingBrs.forEach( function( br ){ br.parentNode.removeChild( br ); }); http://jsfiddle.net/jL8jkkt0/ 注意源代码中<br />元素的字符串表示是不可知的。

Helper functions & prototype methods to replace heavy frameworks?

All frameworks aside, what are some of the common helper functions/prototype methods you use on a daily basis? Please note I am not arguing against frameworks. I've simply found that the majority of what I do on a daily basis can, most often, be done with a few dozen Array, String and Element.prototype methods. With the addition of a few helper functions like $ (getElementsById) and $$$ (

帮助函数和原型方法来取代重型框架?

抛开所有的框架,你每天使用哪些常见的帮助函数/原型方法? 请注意,我并不反对框架。 我简单地发现,我每天做的大多数事情通常可以用几十个Array,String和Element.prototype方法完成。 通过添加一些像$(getElementsById)和$$$(getElementsByClass)这样的辅助函数,我能够满足一些重要框架的核心优势,无论是基本优势。 如果您要收集一些基本方法和函数的小库以取代某些流行框架的核心功能,它们会是什么? 从jQuer

string.replace("é", "e") not working

I have function that is supposed to "clean" a string and i'd like to use replace() to do that, but I can't figure out why the following code is not working when the text comes from an input[text]. for instance : console.log(getCleanText("ééé")); // works fine, it displays : eee but // my_id is an input with type="text" var my_text = document.getElementById("my_id").value c

string.replace(“é”,“e”)不起作用

我有应该“清理”一个字符串的函数,我想使用replace()来做到这一点,但我不明白为什么下面的代码不工作时,文本来自输入[文本] 。 例如 : console.log(getCleanText("ééé")); // works fine, it displays : eee 但 // my_id is an input with type="text" var my_text = document.getElementById("my_id").value console.log(getCleanText(my_text)); // doesn't work at all, it displays : ééé 该功能码是: function

Convert UNIX Time to mm/dd/yy hh:mm (24 hour) in JavaScript

I have been using timeStamp = new Date(unixTime*1000); document.write(timeStamp.toString()); And it will output for example: Tue Jul 6 08:47:00 CDT 2010 //24 hour time Screen real estate is prime, so I would like to take up less space with the date and output: mm/dd/yy hh:mm //also 24 hour time Just add an extra method to the Date object, so you can reuse it as much as you want. Fi

在UNIX中将UNIX Time转换为mm / dd / yh hh:mm(24小时)

我一直在使用 timeStamp = new Date(unixTime*1000); document.write(timeStamp.toString()); 它会输出例如: 星期二7月6日08:47:00 CDT 2010 // 24小时的时间 屏幕的房地产是主要的,所以我想占用更少的空间与日期和输出: mm / dd / yh hh:mm //也是24小时的时间 只需向Date对象添加一个额外的方法,以便您可以随意使用它。 首先,我们需要定义一个辅助函数String.padLeft : String.prototype.padLeft = func

replace multiple occurences in a string with javascript

I have a selectbox with parameters as the value in the option, set like this: <option value="{$i.tileid}androoftiletypeeq{$i.model}andproducenteq{$i.producent}">{$i.name} {$i.$title}</option> I am trying to replace all "and" and "eq" to "&" and "=", but I can only get my javascript to replace the first occurrence. The form is named / ID&#

用javascript替换字符串中的多个出现

我有一个选择框,其参数作为选项中的值,如下所示: <option value="{$i.tileid}androoftiletypeeq{$i.model}andproducenteq{$i.producent}">{$i.name} {$i.$title}</option> 我试图用“&”和“=”替换所有的“和”和“eq”,但我只能让我的javascript替换第一个出现。 该表格被命名为/ ID'ed“rooftile_select $("#rooftile_select").change(function(event) { event.preventDefault(); var data = $("#rooft

MooTools and Array prototype

Mootools is overridding the Array prototype, and the problem is that this prototype and I have an external .js (a library that I can't modify manually) that iterates using for(i in someArray) and it is throwing exception, since now Array has more properties. Any ideas of how to overcome this problem ? I was thinking about removing those properties from array on the Mootools library itself,

MooTools和Array原型

Mootools重写了Array原型,问题是这个原型和我有一个外部的.js(我无法手动修改的库)迭代使用for(i in someArray)并且抛出了异常,因为现在Array有更多的属性。 任何想法如何克服这个问题? 我正在考虑从Mootools库本身的数组中移除这些属性,但看起来并不那么容易。 首先,你应该使用一个正则for(var i=0; i < arr.length; i++) { var el = arr[i]; } for(var i=0; i < arr.length; i++) { var el = arr[i]; }数组

Pros/Cons of not using the prototype chain and returning objects instead

I'm starting to understand javascript, but are there any benefits of using javascript objects like so ... var Person(name, age) { var obj = { species: "Homo sapien", location: "Earth" }; obj.name = name; obj.age = age; return obj; } var Mike = Person("Mike", 17); // => { ... name: "Mike", age: 17} versus the standard var personProtoype = { name:

不使用原型链和返回对象的优点/缺点

我开始理解JavaScript,但是有没有使用javascript对象的好处... var Person(name, age) { var obj = { species: "Homo sapien", location: "Earth" }; obj.name = name; obj.age = age; return obj; } var Mike = Person("Mike", 17); // => { ... name: "Mike", age: 17} 与标准相比 var personProtoype = { name: "anon", age: 0, species: "Homo sapien", locatio

Revisiting extending native prototypes after ECMAScript 5

Recently, given the changes to defining properties in ECMAScript 5, I have revisited the question of whether we can safely extend the native JavaScript prototypes. In truth, all along I have extended prototypes like Array and Function, but I avoided doing so with Object, for the obvious reasons. In unit testing with Jasmine, by adding Object.prototype specs to specs for my own personal framewor

在ECMAScript 5之后重新审视扩展的原生原型

最近,鉴于在ECMAScript 5中定义属性的变化,我重新讨论了我们是否可以安全地扩展原生JavaScript原型的问题。 事实上,我一直在扩展像Array和Function这样的原型,但是我避免使用Object来这么做,原因很明显。 在使用Jasmine进行单元测试时,通过将Object.prototype规范添加到我自己的个人框架规范中,使用非枚举函数扩展Object.prototype似乎是安全的。 但是,像“类型”属性这样的数据属性,使用任何异常处理的getter / sette

Native way to merge objects in Javascript

Javascript's Object doesn't have any native merge operation. If you have two objects, say {a:1, b:2} {c:3, d:4} And want to get {a:1, b:2, c:3, d:4} As far as I know, you have to iterate through the objects. That is to say that you decide on either a merge left or merge right strategy and then you do something like (simplified) for (key in object2) { object1[key] = object2[key];

原生的方式来合并Javascript中的对象

Javascript的对象没有任何本地合并操作。 如果你有两个对象,比如说 {a:1, b:2} {c:3, d:4} 并想要得到 {a:1, b:2, c:3, d:4} 据我所知,你必须迭代对象。 也就是说,你决定合并左边还是合并右边的策略,然后你做一些事情(简化) for (key in object2) { object1[key] = object2[key]; } 这可以。 但是,Javascript具有call和prototype功能。 例如,将arguments转换为Array可以用来完成 Array.prototype.slice.cal

OO JQuery and classes

I'm working on a site and using JQuery for essentially the first time. I've mostly used MooTools for previous projects, and I have a few widget classes I've written using the MooTools Class structure. I'd like to port them over to JQuery, but it looks to me like there is nothing similar to the MooTools functionality when it comes to object classes. I've searched around a b

OO JQuery和类

我正在一个网站上工作,基本上第一次使用JQuery。 我以前的项目主要使用MooTools,并且我使用MooTools Class结构编写了一些小部件类。 我想将它们移植到JQuery上,但在我看来,对于对象类来说,MooTools没有什么功能。 我搜索了一下,并没有发现太多。 Digg似乎已经推出了自己的,但我不知道这是我应该使用的东西。 有没有更好的办法? 人们通常使用JQuery获得面向对象的方法吗? 封装UI小部件(或任何功能类结构)的常