javascript中的數(shù)字與字符串相加實例分析
更新時間:2011年08月14日 16:27:33 作者:
javascript中的數(shù)字與字符串相加實例分析,學(xué)習(xí)js的朋友可以參考下。
復(fù)制代碼 代碼如下:
console.log('----1----')
console.log('12' + '34')//'1234'
console.log('12' + 34 )//'1234'
console.log(12 + '34')//'1234'
console.log(12 + 34 )//46
console.log('----2----')
console.log(+'12' + '34')//'1234'
console.log(+'12' + 34 )//46
console.log(+12 + '34')//'1234'
console.log(+12 + 34 )//46
console.log('----3----')
console.log(-'12' + '34')//'-1234'
console.log(-'12' + 34)//22
console.log(-12 + '34')//'-1234'
console.log(-12 + 34)//22
console.log('----4----')
console.log('12' - '34')//-22
console.log('12' - 34)//-22
console.log(12 - '34')//-22
console.log(12 - 34)//-22
console.log('----5----')
console.log(+'12' - '34')//-22
console.log(+'12' - 34)//-22
console.log(+12 - '34')//-22
console.log(+12 - 34)//-22
console.log('----6----')
console.log(-'12' - '34')//-22
console.log(-'12' - 34)//-22
console.log(-12 - '34')//-22
console.log(-12 - 34)//-22
javascript中字符串連接的同時數(shù)字相加
document.write("<img src='images/" + i + 1 + ".jpg'>")
假如i=1,以上代碼輸出為<img src='images/11.jpg'>
如果想輸出為2.jpg,應(yīng)該這樣寫
document.write("<img src='images/" + (i+1) + ".jpg'>")
您可能感興趣的文章:
- js 字符串轉(zhuǎn)換成數(shù)字的三種方法
- js字符串轉(zhuǎn)換成數(shù)字與數(shù)字轉(zhuǎn)換成字符串的實現(xiàn)方法
- js實現(xiàn)在字符串中提取數(shù)字
- JavaScript數(shù)字和字符串轉(zhuǎn)換示例
- javaScript 判斷字符串是否為數(shù)字的簡單方法
- js判斷是否有6個連續(xù)數(shù)字的字符串的正則
- JS判斷輸入的字符串是否是數(shù)字的方法(正則表達式)
- 利用JS判斷字符串是否含有數(shù)字與特殊字符的方法小結(jié)
- js整數(shù)字符串轉(zhuǎn)換為金額類型數(shù)據(jù)(示例代碼)
- JavaScript實現(xiàn)的數(shù)字與字符串轉(zhuǎn)換功能示例
相關(guān)文章
getElementByID、createElement、appendChild幾個DHTML元素
WEB標(biāo)準(zhǔn)下可以通過getElementById(), getElementsByName(), and getElementsByTagName()訪問2008-06-06JavaScript模板引擎應(yīng)用場景及實現(xiàn)原理詳解
這篇文章主要介紹了JavaScript模板引擎應(yīng)用場景及實現(xiàn)原理,結(jié)合實例形式詳細分析了javascript模版引擎的具體應(yīng)用場景、實現(xiàn)原理、相關(guān)操作技巧與注意事項,需要的朋友可以參考下2018-12-12小程序跳轉(zhuǎn)到的H5頁面再跳轉(zhuǎn)回跳小程序的方法
這篇文章主要介紹了小程序跳轉(zhuǎn)到的H5頁面再跳轉(zhuǎn)回跳小程序的方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03javascript實現(xiàn)根據(jù)函數(shù)名稱字符串動態(tài)執(zhí)行函數(shù)的方法示例
這篇文章主要介紹了javascript實現(xiàn)根據(jù)函數(shù)名稱字符串動態(tài)執(zhí)行函數(shù)的方法,結(jié)合實例形式分析了JS函數(shù)名的判斷及函數(shù)動態(tài)調(diào)用相關(guān)操作技巧,需要的朋友可以參考下2016-12-12JavaScript常用語句循環(huán),判斷,字符串換數(shù)字
這篇文章主要介紹了JavaScript常用語句主要包括對循環(huán),判斷,字符串換數(shù)字相關(guān)資料的介紹,具有一定的參考價值,需要的小伙伴可以參考一下具體內(nèi)容2021-12-12JavaScript與DropDownList 區(qū)別分析
大家都知道,.NET中一些Web服務(wù)器控件解析并編譯,最終被渲染的時候,其實是轉(zhuǎn)化成了普通的html控件。2010-01-01