ASP/Javascript - 将 ASP 值发送到 Javascript 函数
是否可以使用 ASP 脚本中的值调用 JS 函数?
我认为这是可能的,所以我尝试了以下方法,但我似乎无法让它运行。正如您所看到的,我在 JS 调用中有一个 ASP 变量“totalPages”。
Response.Write "<form name=""pageSkip"" onsubmit=""return validatePageSkip("&totalPages&")"">"
然后我就有了 JS 函数,即:
function validatePageSkip(totalPages)
{
if (document.pageSkip.pn.value.length > totalPages)
{
alert("Please enter a page number within range!");
document.pageSkip.pn.focus();
return(false);
}
document.pageSkip.submit();
}
- 这可能吗?
- 如果是,我做错了什么?
更新
当我使用空文本框提交时,仅使用此功能甚至无法工作:
Response.Write "<form name=""pageSkip"" id=""pageSkip"" onsubmit=""return validatePageSkip()"" method=""post"" action=""?cpr="&pageRange&"#main"">"
Response.Write "<input type=""text"" name=""cpn"" id=""cpn"" spellcheck=""false"" autocomplete=""off"" size=""3"" class=""pageSkipBox"" value="""¤tPage&""">"
Response.Write "</form>"
使用这个简单的 JS 函数:
function validatePageSkip()
{
if (document.pageSkip.cpn.value.length < 1)
{
alert("Test!");
document.pageSkip.cpn.focus();
return(false);
}
document.pageSkip.submit();
}
我真的不知道出了什么问题。表单完美提交,但它只是不会调用该函数。
你能发现什么吗?
Is it possible to call a JS function, with a value from an ASP script?
I thought it was possible, so I tried the following method but I can't seem to get it to run. As you can see, I have an ASP variable "totalPages" in the JS call.
Response.Write "<form name=""pageSkip"" onsubmit=""return validatePageSkip("&totalPages&")"">"
I then have the JS function, which is:
function validatePageSkip(totalPages)
{
if (document.pageSkip.pn.value.length > totalPages)
{
alert("Please enter a page number within range!");
document.pageSkip.pn.focus();
return(false);
}
document.pageSkip.submit();
}
- Is this possible?
- If yes, what am I doing wrong?
UPDATE
It won't even work just using this, when I submit with an empty text box:
Response.Write "<form name=""pageSkip"" id=""pageSkip"" onsubmit=""return validatePageSkip()"" method=""post"" action=""?cpr="&pageRange&"#main"">"
Response.Write "<input type=""text"" name=""cpn"" id=""cpn"" spellcheck=""false"" autocomplete=""off"" size=""3"" class=""pageSkipBox"" value="""¤tPage&""">"
Response.Write "</form>"
With this simple JS function:
function validatePageSkip()
{
if (document.pageSkip.cpn.value.length < 1)
{
alert("Test!");
document.pageSkip.cpn.focus();
return(false);
}
document.pageSkip.submit();
}
I really don't know what is wrong. The form submits perfectly but it just won't call the function.
Can you spot anything?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是可能的。但你需要确保你正确地转义你的引号
我个人更喜欢在头脑中做这样的事情
然后
Yes it is possible. but you need to make sure you escape your quotes correctly
Personally I would prefer doing something like this in the head
Then