douyang2530 2016-04-13 12:09
浏览 23
已采纳

将混合字符串和int参数传递给javascript

I've had a look around and can't seem to find a working solution, so here's the requirements.

I'm building a system that takes data from a master page and loads it into a modal style window for quick data processing. I have a javascript function passing 4 status parameters, and whilst 3 of them will always be integers, one of them can be integer or string.

The function works if all 4 parameters are integer, but fails when a string is passed.

function passJob(jobid,equipid,status,location) {

var a = document.getElementById('jobnumber');
var b = document.getElementById('equipid');
var c = document.getElementById('status');
var d = document.getElementById('location');
  a.value = jobid;
  b.value = equipid;  
  c.value = status;  
  d.value = location;  
}

PHP

<a href='#' onclick='passJob($sr,$eid,$ss,$sl);'>Modify Job</a>

$sr, $ss and $sl will always be numeric, $eid will either be integer, or a string starting with M and then having a number after it.

I've tried adding quotes to the variables, around the variables, inside the function etc and no luck :(

  • 写回答

4条回答 默认 最新

  • dp13668681869 2016-04-13 12:13
    关注

    You need to pass as string if you do not know what they are - also make sure you do not nest the same type of quote:

    onclick='passJob($sr,"$eid",$ss,$sl);'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里