簡體   English   中英

嘗試在JavaScript插件中轉義字符串的問題

[英]Issue trying to escape a string in javascript plugin

我正在嘗試為CKEditor使用Bootstrap Tab插件,並且效果很好。 但是,當我在內容上使用單引號時(字符串是否為“'”或“或”都沒關系),它就分手了。

我想這只是一個逃避問題。 我嘗試使用escape()encodeURI() ,但是失敗了。

錯誤:語法錯誤:參數列表后缺少);
來源:x)PRE3015 Pino 1/2''15mm Ponta BalisticaAço3,1 15

選項卡的插件代碼是:

 data: function() { var bootstrapTab_d = new Date(); var bootstrapTab_id = bootstrapTab_d.getTime(); var bootstrapTab_item = bootstrapTab_contents = ''; for (var bootstrapTab_i = 0; bootstrapTab_i <= this.data.bootstrapTab_total; bootstrapTab_i++) { eval("bootstrapTab_title = this.data.bootstrapTab_item" + bootstrapTab_i); bootstrapTab_title = bootstrapTab_title != undefined ? bootstrapTab_title : ''; eval("bootstrapTab_content = this.data.bootstrapTab_content" + bootstrapTab_i); bootstrapTab_content = bootstrapTab_content != undefined ? bootstrapTab_content : ''; eval("bootstrapTab_itemClass = this.data.bootstrapTab_itemClass" + bootstrapTab_i); bootstrapTab_itemClass = bootstrapTab_itemClass != undefined ? bootstrapTab_itemClass : ''; eval("bootstrapTab_contentClass = this.data.bootstrapTab_contentClass" + bootstrapTab_i); bootstrapTab_contentClass = bootstrapTab_contentClass != undefined ? bootstrapTab_contentClass : ''; if (bootstrapTab_title) { bootstrapTab_item += '<li role="presentation" class="' + bootstrapTab_itemClass + '"><a href="#tab' + bootstrapTab_id + '_' + (bootstrapTab_i + 1) + '" aria-controls="tab' + bootstrapTab_id + '_' + (bootstrapTab_i + 1) + '" role="tab" data-toggle="tab">' + bootstrapTab_title + '</a></li>'; bootstrapTab_contents += '<div role="tabpanel" class="' + bootstrapTab_contentClass + '" id="tab' + bootstrapTab_id + '_' + (bootstrapTab_i + 1) + '">' + bootstrapTab_content + '</div>' } } this.element.setAttribute('id', 'collapse' + bootstrapTab_id); this.element.$.innerHTML = '<div role="tabpanel"><ul class="nav nav-tabs" role="tablist">' + bootstrapTab_item + '</ul><div class="tab-content">' + bootstrapTab_contents + '</div></div>' } 

我將重構代碼,而不使用eval!

評估是邪惡的http://blogs.msdn.com/b/ericlippert/archive/2003/11/01/53329.aspx

代替

eval("bootstrapTab_title = this.data.bootstrapTab_item" + bootstrapTab_i);

使用bootstrapTab_item作為數組並執行此操作

bootstrapTab_title = this.data.bootstrapTab_item[bootstrapTab_i]

真的不知道錯誤是否存在,但是我認為找到錯誤的途徑是重構以消除這些評估,這可能是問題的根源。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM