如何使用javascript变量设置属性

Pan*_*ool 5 javascript razor

以下是我在durandal应用程序中的cshtml代码

<script type="text/javascript" src="~/Scripts/require.js" 
  id="countryscript" data-main="**here i have to set value**"></script>
Run Code Online (Sandbox Code Playgroud)

我想用我的javascript变量值设置脚本属性data-main.怎么做到这一点?

我试过了

document.getElementById("countryscript").data-main = countrycode;
Run Code Online (Sandbox Code Playgroud)

它在=符号附近显示语法错误.需要帮忙..

小智 5

试试这个:

document.getElementById("countryscript").setAttribute("data-main", countrycode);
Run Code Online (Sandbox Code Playgroud)