Javascript in Visual studio Web Api
Javascript in Visual studio Web Api
我的html代码中嵌入了一个javascript函数,但当我运行页面时,我会收到以下错误:Uncaught ReferenceError:myFunction未定义。
我也在使用angularjs,所以我有我的索引页,正如他们所解释的,我的部分页,这个函数在我的部分页面中。
当我双击文件夹中的网页时,我可以运行脚本,但当我运行web api时,它会出现错误。
我的javascript函数:
<script type="text/javascript">
function myFunction() {
var x;
var r = confirm("Press a button!");
if (r == true) {
x = "You pressed OK!";
}
else {
x = "You pressed Cancel!";
}
document.getElementById("demo").innerHTML = x;
}
以及我如何称呼它:
<button onclick="myFunction()">Try it</button>
有人能帮我吗?厚度
它似乎在加载函数之前就试图使用它。你能试试下面的吗。
<script type="text/javascript">
function myLoad() {
var myButton = document.getElementById('myButton');
myButton.addEventListener('click', function() {
var x;
var r = confirm("Press a button!");
if (r == true) {
x = "You pressed OK!";
}
else {
x = "You pressed Cancel!";
}
document.getElementById("demo").innerHTML = x;
}, false);
}
window.load = myLoad;
</script>
最后为按钮添加一个Id。
<button id="myButton">Try it</button>
相关文章:
- Steam Web API:I'我不知道该如何处理这个看起来像哈希的url来生成图像
- 如何在visualstudio中调试web api时编辑javascript文件
- 将复杂对象从angular js传递到web api,它总是返回404
- 将文档上载到Web API
- 对/Token的ASP Web API调用间歇性
- 从其他域和计算机发布的 Web API 帖子
- Web API 调用在设备模式下失败
- Testing .NET Web API from JavaScript
- 将日期作为从 Web API 到 angularJS 的 json 响应
- 获取 Spotify 用户 [Web API] 当前播放的曲目名称
- 在我的 Web API 中无法获取我的自定义标头
- Json 参数强制转换继承 Web API 2.
- 使用来自AngularJS的Web API JSON响应-错误:应为和数组,但得到了一个对象
- Javascript in Visual studio Web Api
- 获取AJAX中未定义的值(x),web api
- Web API在JSON调用上返回XML
- 将JSON字符串发布到WEB API
- 如何通过AngularJS$http从ASP.Net Web API 2获取访问令牌
- 使用ASP.Net MVC Web Api将JSON数据导出到Excel工作表
- 从mvc web api httpresponse生成csv,并通过angularjs接收下载