开发者

Javascript insert parameter inside string

开发者 https://www.devze.com 2022-12-25 10:30 出处:网络
I want to ask if there is a way to insert variable inside another string which is part of another statement. For example:

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

精彩评论

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

关注公众号