如何使用javascript变量设置属性
下面是我在durandal应用程序中的cshtml代码如何使用javascript变量设置属性,javascript,razor,Javascript,Razor,下面是我在durandal应用程序中的cshtml代码 <script type="text/javascript" src="~/Scripts/require.js" id="countryscript" data-main="**here i have to set value**"></script> 它在=符号附近显示语法错误。需要帮助。来自 或者,如果您有JQuery,这就容易多了 $('#countryscript').attr("data-main
<script type="text/javascript" src="~/Scripts/require.js"
id="countryscript" data-main="**here i have to set value**"></script>
它在=符号附近显示语法错误。需要帮助。来自
或者,如果您有JQuery,这就容易多了
$('#countryscript').attr("data-main", countrycod);
试试这个:
document.getElementById("countryscript").setAttribute("data-main", countrycode);
$('#countryscript').attr("data-main", countrycod);
document.getElementById("countryscript").setAttribute("data-main", countrycode);