js中 單引號 雙引號 引數問題 單引號 替換成 \' 雙引號 替換成 \" 等
.replace(/\'/g, "\\'") -> ' 替換成 \'
.replace(/\"/g, "\\\"") -> " 替換成\"
注:適用於 onclick='Test("數字雙音\"")'
這種寫法
注:適用於onclick="Test('數字雙音"')" 建議寫法
.replace(/</g, "\\\<") -> < 替換成\<
.replace(/>/g,"\\\>") -> >
正確執行的結果格式示例:
<input type="button" onclick="Test('數字\'雙音"')" value="測試" />
function Test(s) {
alert(s);
}
相關推薦
如何 給 文章 新增 標籤 以及 如何 讓 js 中的資料 跟隨 form 表單 一起提交到 後臺
設計思路 檔案和,標籤的關係,多對多的關係。 需要一個標籤表,和,文章標籤中間表。 文章和,標籤的關係,多對多的關係。 一個標籤對應多篇文章,一篇文章對應多個標籤 。 標籤,增刪改查,可以在後臺管理。 這個文章標籤中間表,是如果1篇文章有幾個標籤,就有幾條資料,只是對應同一個文章id
js中常用的事件,onclick 單擊事件、onblur 失去焦點事件、onchange改變事件、onmouseover滑鼠進入事件、onmouseout滑鼠移除事件、onsubmit提交事件
onclick 單擊事件 onblur 失去焦點事件 onchange 當物件或選中區的內容改變時觸發。 onmouseover 當用戶將滑鼠指標移動到物件內時觸發。 onmouseout 當用戶將滑鼠指標移出物件邊界時觸發。 onsubmit 當表單將要被提交時觸發。
在js中獲取位址列引數
在js中獲取位址列引數 //根據傳遞過來的引數name獲取對應的值 function getParameter(name) { var reg = new RegExp("(^|&)" + name + “=([^&]*)(&|$)”,“i
js中的型別和函式引數傳遞型別問題
js中的型別: 2大型別:原始型別和物件。 原始型別有 boolean、number、string這三個普通原始型別,還有null、undefined這倆特殊原始型別 物件嘛就多了,普通物件、內建物件、全域性物件、函式、陣列等。 函式引數傳遞型別: 對於原始型別,傳遞的是值,
js中 單引號 雙引號 引數問題 單引號 替換成 \' 雙引號 替換成 \" 等
.replace(/\'/g, "\\'") -> ' 替換成 \' .replace(/\"/g, "\\\"") -> " 替換成\" 注:適用於 onc
JS中的單引號和雙引號
ont 進行 成對 在外 可讀性 編譯 afa 來看 遇到 JS裏面的單引號和雙引號可以同時使用,但是要遵循一定的準則。 最外面用了雙引號了,那麽裏面就不能再用雙引號了,因為引號是成雙對的,瀏覽器讀到一個雙引號後,到第2個雙引號時才算結束;同理,瀏覽器讀到一個單引號後,必須
js中單引號和雙引號的使用區別
1.引入 在jquery或者js中拼接字串時,使用單引號和雙引號是沒有區別的,都可以被成功解析成字串,但是,在一些複雜的字串拼接時,需要單引號和雙引號的混合使用時,就需要注意了。最近在專案中寫js指令碼時,發現firebug經常會報多一個單引號或者多一個雙引號這種低階錯誤。但是要是搞不清這兩者,你就
Js中的單引號與雙引號
單引號和雙引號其實沒啥區別,看你自己習慣了 <input type="button" onclick="alert("1")">-------------------不正確 <input type="button" onclick="alert('1')
Js中的單引號與雙引號問題
2.單引號包含雙引號的時候,裡面的雙引號不用轉義,反之亦然 看下面程式碼: <input type="button" onclick="alert("3")">-------------------不正確 <input type="button" onclick="alert('3')"
js中字元的替換(如用單引號提換雙引號)
最近遇到一個問題,需要將Json轉為String( js中json物件和string互轉 ),String物件內的單引號需要為雙引號,就查了一下,做了一個總結。 JS提供的replace()方法正好解決了字元替換的問題。 stringObject.replace(reg
js 中的雙引號和單引號使用總結
單引號和雙引號其實沒啥區別,看你自己習慣了 <input type="button" onclick="alert("1")">-------------------不正確 <input type="button" onclick="alert('1')"
js 中雙引號與單引號混合使用的問題
js 中雙引號與單引號 程式碼塊 雙引號中巢狀雙引號引起的問題 錯誤程式碼 : var li = "<li><a href="#">"+item.cname+"<
js中單引號和雙引號
從 html 的角度考慮,確實用單引號會方便很多。但如果是單純的 .js 檔案,我傾向於使用雙引號。 1. 因為 ES6 引入了 template string,template string 用的分隔符 [ ` ] 看起來和單引號[ ' ] 太像了,容易搞混。我們在專案中遇到過,有人在使用單引號字串裡誤用了
Python中單引號,雙引號,三個單引號,外雙單引號內雙引號,外雙引號內單引號的區別
Python 中一對單引號和一對雙引號都可表示一個字串: 1 Str1 = 'python' 2 Str2 = "python" 思考? 如何表示字串: I ' am a python coder. 方法一, 用單引號加轉義字元 ' \ ': 1
在js裡雙引號裡又加單引號的解決方案常用WdatePicker
EndTime: '<input name="EndTime" type="text" class="editable center decimal" isvalid="no" check
js使用<c:out/>處理單引號,雙引號混合顯示
數據庫字段 處理 不能 字符 顯示 包含 正常 字段 數據庫 一,問題 數據庫存儲字段中包含單引號和雙引號,頁面js獲取值時使用el表達式取值不能正常處理 二,例 數據庫字段contents:"新年快樂",‘萬事如意‘var content = &quo
shell中" "(雙引號)與 ' '(單引號)的區別
" "(雙引號)與 ' '(單引號)的區別 你在shell prompt後面敲打鍵盤、直到按下enter的時候
js中嵌入jsp(html)代碼的雙引號轉換問題--事件沒反應
-s cancel btn log span pic fault pda eight 下面是一段今天遇到問題的代碼,select中寫了onchange事件 ,在沒有加轉義的情況下,F12解析的代碼是錯亂的,雙引號與內容中寫的不一致,還會有空格出現,經過一段時間的摸索,發現在
js 中使用el表達式 關鍵總結:在js中使用el表達式一定要加雙引號
fine function alt num length nump string ima ets js 中使用el表達式 關鍵總結:在js中使用el表達式一定要加雙引號 js控制中用到了el表達式,最開始源碼如下: Java代碼 var selected =
MySql中 where IN 字串自動新增單引號問題
mysql查詢語句where條件in 正常情況需要查詢的語句: select *from temp where id in ('1','2','3','4','5') 在實際過程中發現一直查不出資料,實際上能夠查出資料,弄得一直很鬱悶,找不出原因。 通過各終嘗