DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> javascript中的數字與字符串相加實例分析
javascript中的數字與字符串相加實例分析
編輯:關於JavaScript     
復制代碼 代碼如下:
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中字符串連接的同時數字相加
document.write("<img src='images/" + i + 1 + ".jpg'>")
假如i=1,以上代碼輸出為<img src='images/11.jpg'>
如果想輸出為2.jpg,應該這樣寫
document.write("<img src='images/" + (i+1) + ".jpg'>")
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved