【问题标题】:Unable to figure out why input parameter is becoming null无法弄清楚为什么输入参数变为空
【发布时间】:2022-09-15 21:09:06
【问题描述】:

这是我的 gsp 页面中的脚本:

<script>
function getItemsLength(){
    var id = document.getElementsByName("franchiseID")[0].value(); 
    alert(id); //This displays the intended id
    var itemLength = ${storeCommand.numOfBranches(id)}; //The id becomes null when sent here
} 
</script>

此函数称为按钮的 onclick,我无法通过 store 命令本身访问 id,因为页面尚未保存 - 它显示为 null。本质上,我获取用户为特许经营权提供给我的 ID,然后我查询有多少商店拥有该特许经营商 ID 以将其显示在屏幕上。

我是 grails 和 web 开发的新手,所以如果我做错了什么,请告诉我!

【问题讨论】:

  • value 不是函数。您应该在分配id 的行上收到错误消息。
  • 没有函数getElementByName,它是getElementsByName。当您发布问题时,您显然犯了复制错误,那么我们如何才能知道您的真正问题是什么。

标签: javascript grails gsp


【解决方案1】:

您在这里遇到的基本问题是您试图混合客户端编程和服务器端编程。 ${storeCommand.numBranches(id)} 在呈现 HTML 时被处理,在这种情况下 id 不在范围内。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-22
    • 2015-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多