In my html page i have this code:
onclick="javascript:CheckAdd({document.getElementById('user_btn').value,document.getElementById('txt_btn').value});
but when i click on button debugger say:
Uncaught SyntaxError: Unexpected token .
what's wrong in my call?
so many thanks in advance
You are passing an object to the CheckAdd
function, this object must contain keys for each value:
onclick="CheckAdd({ key1: document.getElementById('user_btn').value, key2: document.getElementById('txt_btn').value });
Without the keys, your syntax is invalid.
However, if the checkAdd
functions takes two argument and not an object, call it without the brackets, like this:
onclick="CheckAdd(document.getElementById('user_btn').value, document.getElementById('txt_btn').value);
You missed to add key.
onclick="javascript:CheckAdd({k1: document.getElementById('user_btn').value, k2: document.getElementById('txt_btn').value});
If you dont want to pass object pass an array.
删除{ }
并重试或使用这样的参数
{v1:document.getElementById('user_btn').value,v1:document.getElementById('txt_btn').value }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.