Use variable in jQuery selector [duplicate]

戏子无情 提交于 2019-12-01 14:03:57

use

$('.onchange :checkbox[idurl="apple"' + number+']').prop('checked', false);

Breaking of string:

1st part '.onchange :checkbox[idurl="apple"'

2nd part number

3rd part of string ']'.

I believe it's because it is inside your single quotes. Try this instead:

$('.onchange :checkbox[idurl="apple"' + number + ']').prop('checked', false);

You need to call the function with an actual number where your number argument in the function is. Also, javascript doesn't recognize variables in quotes, so you need to escape your single quotes.

$('.onchange :checkbox[idurl="apple"' +number +']').prop('checked', false);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!