douhuang2218 2011-04-20 18:34
浏览 42
已采纳

Javascript问题 - 没有正确地将带有'0'的字符串传递给字符串

I have a weird problem. I have a simple function to open a popup with information about a pin (by clicking on a link with that PIN)

It works fine for some pins, but converts others to a different number.

For example passing '033604' opens http://mysite.com/pincheck.php?pin=014212

but passing '023960' opens http://mysite.com/pincheck.php?pin=023960 (what I need)

Passing '032765' opens http://mysite.com/pincheck.php?pin=013813

but passing '030309' opens http://mysite.com/pincheck.php?pin=030309 (what I need)

I've tried a bunch of pins and it's all random like that - either passes the correct pin or converts it to a different number

The function is

function win_open_pin(pin) {
newwindow = window.open('pincheck.php?pin=' + '0' + pin + '' , 'popupwin', 'menubar=no,history=no,resizable=yes,scrollbars=yes,toolbar=no,width=650,height=300');
if (window.focus) {newwindow.focus()}
}

I did try using pincheck.php?pin=0' + pin and did try pin = toString(pin) in the function - no use

The call is also simple

<a href=\"javascript:win_open_pin($pin)\">$pin</a> 

The $pin variable in php is taken from the db and is a string, I even did (string) casting just in case. It seems to be js issue, as I never had issues like that with php.

I don't see any rhyme or reason to this. Hope someone can point me in the right direction to solve this. Thanks.

  • 写回答

2条回答 默认 最新

  • duanlin1933 2011-04-20 18:40
    关注

    I think its an issue with the automatic int conversion. e.g:

    parseInt("033604", 10) //returns 33604
    
    parseInt("033604") //returns 14212 - Octal
    

    Change the anchor element markup to following(notice the single quotes around $pin):

    <a href=\"javascript:win_open_pin('$pin')\">$pin</a>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂