开发者

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 %>");
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜