简体   繁体   English

从js引用标签功能?

[英]Refer tag function from js?

I have this code in my jsp 我的jsp中有此代码

    <script  type="text/javascript">

    function myJsFunction() {
       var queryString = new QueryString();
        queryString.add('initDate', document.getElementById('${id}').value);
    }

And it is working. 它正在工作。 I want document.getElementById('${id}').value to pass throught my tag lib and I add 我希望document.getElementById('${id}').value通过我的标签库,然后添加

 <%@ taglib prefix="my" uri="http://tags/my"%>


    <script  type="text/javascript">

    function myJsFunction() {
       var queryString = new QueryString();
        queryString.add('initDate', ${my:myTagFunc(document.getElementById('${id}').value)});
    }

But is slowing empty despite that document.getElementById('${id}').value returns a String. 但是,尽管有document.getElementById('${id}').value返回一个String,但它正在放慢速度。 I can not understand why? 我不明白为什么?

You are mixing two different codes. 您正在混合两个不同的代码。 The key is to realize, where and when each code is executed - JSP on the server when the page is requested and rendered (ie before the response is sent to the browser) and Javascript in the browser, after the browser receives the already generated response. 关键是要实现何时 何地执行每个代码-请求和呈现页面时(即将响应发送到浏览器之前)服务器上的JSP,以及在浏览器收到已经生成的响应之后在浏览器中使用Javascript 。

As commented by Satpal, you need AJAX . 正如Satpal所说,您需要AJAX

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM