简体   繁体   English

使用onclick的href上的多个属性

[英]Multiple attribute on href using onclick

I Tried this code to get multiple value in href but it does not work. 我尝试使用此代码来获取href中的多个值,但是它不起作用。 any problem on this one ? 这个有什么问题吗?

 <a  href=""onclick="this.href='printsales.php?CUSTOMERID='+document.getElementById('CUS_CODE_MX').value'&AGE='+document.getElementById('AGEID').value" target="_blank">Print</a>

You are missing a + sign between a string and a value. 您在字符串和值之间缺少+号。

The error is between this two 错误在这两者之间

document.getElementById('CUS_CODE_MX').value '&AGE='

Correct format 正确格式

document.getElementById('CUS_CODE_MX').value + '&AGE='

Every time you join a value and a string, you need a + sign 每次连接一个值和一个字符串时,都需要一个+

Even if you are joining two strings 即使您要连接两个字符串

'Hello'+ 'World' “ Hello” +“ World”

Pliss avoid long js as an inline atribute. Pliss避免将长js作为内联属性。 I will recommend you call a function as the onclick attribute. 我建议您将函数称为onclick属性。

Hope this helps :) 希望这可以帮助 :)

<a  href=""onclick="this.href='printsales.php?CUSTOMERID='+document.getElementById('CUS_CODE_MX').value+'&AGE='+document.getElementById('AGEID').value" target="_blank">Print</a>

It's better to use external script for that rather than inline format. 最好使用外部脚本而不是内联格式。 And just add missing + to your code. 只需在代码中添加缺少的+ Also, using variables would clean up the code. 同样,使用变量将清理代码。

 function func() { var CUS_CODE_MX = document.getElementById('CUS_CODE_MX').value; var AGEID = document.getElementById('AGEID').value; this.href = 'printsales.php?CUSTOMERID='+CUS_CODE_MX+'&AGE='+AGEID; } 
 <a href="" onclick="func()" target="_blank">Print</a> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM