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 组策略中的计算机配置策略无法下发
  • ¥15 机器学习简单问题解决
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写