gpt4 book ai didi

Javascript在字符串中插入参数

转载 作者:行者123 更新时间:2023-11-28 10:32:51 24 4
gpt4 key购买 nike

我想问是否有一种方法可以将变量插入另一个语句的另一个字符串中。例如:

function SomeFunction(field) {  

var someVariable = document.getElementById('<%=' + field + '.ClientID %>');
}

但是我有一个错误:

Error   6   'string' does not contain a definition for 'ClientID'

谢谢。

最佳答案

您无法从服务器端标记获取值,这不起作用:

<%=' + field + '.ClientID %>

你需要以某种方式做到这一点,所以你只能这样做:

var someVariable = document.getElementById(field);

关于Javascript在字符串中插入参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2577418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com