[英]Uncaught ReferenceError: lookup is not defined at HTMLButtonElement.onclick
I keep getting this syntax error on the browser. 我一直在浏览器上遇到这种语法错误。 I am not sure what am I missing here. 我不知道我在这里错过了什么。
Basically I am trying to make a request to an external web api which takes an array of checked check box values as parameters passed in query parameter. 基本上我正在尝试向外部Web api发出请求,该请求将一组已检查的复选框值作为查询参数中传递的参数。
Here is my javascript. 这是我的javascript。
function lookup() {
var query = document.getElementById("sform").value;
// var res = PageMethods.lookupfromjs_Click(query, onSuccess, onError);
var dttypeList;
$('#Button1').click(function() {
$('input[type=\"checkbox\"]').each(function(){
dttypeList.push(this.name);
alert( $.toJSON(dttypeList));
});
});
}
Here is the html 这是html
<!DOCTYPE html>
<head runat="server">
<title></title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js" type="text/javascript"></script>
<script src="Scripts/lookup.js" type="text/javascript"></script>
<script src="Scripts/getdatatype.js" type="text/javascript"></script>
</head>
<body>
<section class="webdesigntuts-workshop">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" >
</asp:ScriptManager>
<div>
<asp:TextBox type="search" name="search" id="sform" placeholder="What are you looking for?" runat="server" />
<asp:TextBox type="search" name="hdnText" id="hdnText" runat="server" />
<button id="Button1" onclick="lookup()" type="button">Search</button>
</div>
<div>
<p> </p>
</div>
<div>
<button id="Getdtbtn" type="button" onclick="getDatatypes()">Get Datatypes</button>
</div>
</form>
</section>
</body>
</html>
Does the lookup function even need to be declared? 是否需要声明查找功能? With the limited HTML snippet you posted, I tried to cobble something closer together resembling what you may have been trying to achieve: 使用您发布的有限HTML片段,我尝试将更接近的内容拼凑在一起,类似于您可能尝试实现的内容:
var query = document.getElementById('sform').value; var dtypeList = []; $('#Button1').click(function() { $('input[type="\\checkbox\\"]').each(function() { dtypeList.push(this.name); alert(JSON.stringify(dtypeList)); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form id="sform"> <label for="Hello">Hello</label> <input type="checkbox" name="Hello"> <label for="World">World</label> <input type="checkbox" name="World"> <button id="Button1" type="button">Search</button> </form>
This still loops through all of the checkboxes and spits them out to an alert once you click the button. 这仍然会遍历所有复选框,并在您单击按钮后将其吐出警报。
Also, please refer to this post about $.toJSON(): https://stackoverflow.com/a/7759630/3611025 另外,请参阅这篇关于$ .toJSON()的帖子: https ://stackoverflow.com/a/7759630/3611025
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.