onclick中字符串转义,函数调用的问题
2016-10-19 10:44
232 查看
<span style="font-size:24px;">return '<button class="bt_row" data-toggle="modal" onclick="resi(\''+c.residentName+'\')">预约</button>';</span>
<span style="font-size:24px;"><span style="font-family: SimSun; background-color: rgb(255, 255, 255);">碰到的问题:</span></span>想要实现的结果:点击button,调用函数resi,并将参数传给此函数。但是参数并不是一个固定的,而是从后台读出来的,必须进行解析。
当写成这样的时候:
<span style="font-size:24px;">return '<button class="bt_row" data-toggle="modal" onclick="resi('+c.residentName+')">预约</button>';</span>其中
<span style="font-size:24px;">onclick="resi('+c.residentName+')"</span>
中 '+c.residentName+' 已经是一个字符串了,而就会变成resi(+c.residentName+),其中+c.residentName+ 已经被当成参数,此时+c.residentName+并没有转义和解析。
所以:当写成
<span style="font-size:24px;">onclick="resi(\''+c.residentName+'\')"</span>的时候,浏览器可以解析为'+c.residentName+'是一个变量,根据后台不同的值,从而解析为所选择的字符串或者其他的。
但是如果是number的话,
<span style="font-size:24px;"> onclick="resi('+c.residentNO+')"</span>
这样就可以的,因为数字不用解析,可以直接被读到。
相关文章推荐
- C# 调用 C++ dll 函数 时传递字符串 需要注意的问题
- C# 调用 C++ dll 函数 时传递字符串 需要注意的问题(zz)
- C# 调用 C++ dll 函数 时传递字符串 需要注意的问题
- 关于动态存储分配函数的调用,在已经过排序的数组中查找及删除内容的操作,余数的分析,删除字符数组中的空格,对链表的逆置,在源字符串中查找子字符串的个数,函数指针以及函数的调用,循环赋值带来的问题以及插入
- CString的几个字符串处理函数的index问题
- 关于VC开发中的函数调用问题
- 请指教:prototype.js ajax里面onSuccess 里面调用 公有成员函数的问题
- 同一页面两次调用分页函数的问题
- 用内嵌汇编来解决运行时参数不确定的函数的调用问题
- InstallShield自定义函数在各版本间调用的问题
- pb中调用外部库函数压缩文件夹的问题!急!
- .net中前台javascript与后台c#函数相互调用问题
- .net中前台javascript与后台c#函数相互调用问题
- .net中前台javascript与后台c#函数相互调用问题
- 调用javascript遇到奇怪的“函数未定义”问题
- 请指教:prototype.js ajax里面onSuccess 里面调用 公有成员函数的问题
- 一次调用ACTIVEX控件中出现的问题.不可访问构建函数.
- 通过调用顺序表函数来求解“约瑟夫问题”
- .net中前台javascript与后台c#函数相互调用问题