Javascript, add a string if it is true - codesd.com
source link: https://www.codesd.com/item/javascript-add-a-string-if-it-is-true.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Javascript, add a string if it is true
I need to modify this function:
function checkPermissions(fid, obj) {
$("#permissions_"+fid+"_canview").attr("checked", obj.checked);
}
if the param "n" is "true" then instead of #permissions it'll output #permissionsSet.
is that possible?
OP clarified the question to be change this whether or not a 3rd parameter was provided. Here you go.
function checkPermissions(fid, obj, n) {
var id = n !== undefined ? '#permissionsSet' : '#permissions';
$(id + fid + "_canview").attr("checked", obj.checked);
}
Note: This function can be freely used with passing 2 or 3 parameters (or really any number).
checkPermissions(1, this); // Ok n === undefined
checkPermissions(1, this, true); // Ok n === true
checkPermissions(1); // Okish n and obj === undefined
Related Articles
Add a string to the Javascript expression
how to add a string at the end of the pointer to the pointer (** pointer) at C
How to add editText strings to a list
Automatically add request string from page request to outbound page request in ASp.NET WebForms
how to add a string to the entire array element?
How to add a string value in the php array
Add a string to an autoname gnuplot
Add a string to the contents of the file
Find a way to add a string to a tuple
How do I add a string to the beginning of a file collection name in another directory using a shell
Trying to Add a String Value to an SQL Database - Help and Tips
Groovy / Grails dynamically adds a String field
Add query string (s) to the end of the url using the routes in ASP.NET MVC3
Can I get a list from an object, add a string to it, and deliver it to the object in a single line?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK