What is wrong with my code. How do i pass attrfull to the 开发者_运维知识库inside. The way i have it done, if i run the function editsubmit($selected, size)
, $selected is inserted properly but i'm getting attrfull instead of size.
function editsubmit(attr, attrfull) {
if (attr.length) {
attr.val().length ? $selectedinput.attr({
attrfull: attr.val()
}) : $selectedinput.removeAttr(attrfull);
}
}
$selected is a variable and attrfull i a string. Do i need double qoutes around the string when i run the function like editsubmit($selected,'size')
.
Try
function editsubmit(attr, attrfull) {
if (attr.length) {
attr.val().length ? $selectedinput.attr(attrfull, attr.val()) : $selectedinput.removeAttr(attrfull);
}
}
Yes, you do need it to be a string (in double quotes), or else it will think you're trying to pass a variable reference.
The problem is this: {attrfull: attr.val()}
I think you want it to be {size: (whatever attr.val() is)}
So:
function editsubmit(attr, attrfull) {
if (attr.length) {
if (attr.val().length) {
var myObj = {};
myObj[attrfull] = attr.val();
$selectedinput.attr(myObj);
} else {
$selectedinput.removeAttr(attrfull);
}
}
}
精彩评论