Javascript insert parameter inside string
I want to ask if there is a way to insert variable inside another string which is part of another statement. For example:
function SomeFunction(field) {开发者_开发知识库
var someVariable = document.getElementById('<%=' + field + '.ClientID %>');
}
But I've got an error:
Error 6 'string' does not contain a definition for 'ClientID'
Thank you.
You can not get a value from server-side tags, this won't work:
<%=' + field + '.ClientID %>
You need to do it some way so you only do this:
var someVariable = document.getElementById(field);
Assuming field is say 'name' and you give id to name field as "name.4" where 4 is ClientID.
function SomeFunction(field) {
var someVariable = document.getElementById(field+".<%= ClientID.to_s %>");
}
精彩评论