jsp的button onclick事件 如何传带html标签的参数给js,下面的代码传简单的文字没有问题,但是传图文混排的文本就有问题了。
这是jsp:
<button type="button" onclick="f_show('${title}','${content}');">相关内容</button>
<label id="show"/>
这是js:
<script type="text/javascript">
function f_show(title,content)
{
document.getElementById("show").innerHTML = title+"<br>"+content;
}
</script>查资料说,用escape和unescape编解码,但不会用。请各位高手帮帮小弟。JSPJavaScriptHTML标签函数

解决方案 »

  1.   

    <button type="button" onclick="f_show('escape(${title}'),'escape(${content})');">相关内容</button>document.getElementById("show").innerHTML = unescape(title)+"<br>"+unescape(content);是这样吧
      

  2.   

    我按照一楼的写法,试了,结果,jsp页面:
    在页面右键查看源文件:
    <button type="button" onclick="f_point('escape(NBA)','escape(<p> 美国东部、西部联盟<img alt="" src="/examstudy/userfiles/images/Desert(1).jpg" style="width: 200px; height: 150px" /></p>)');">相关知识点</button>
    请高手再指点,谢谢啦。
      

  3.   

    又琢磨了好久,终于搞定了。解决方案:
    <script type="text/javascript">
    var t=escape('${title}');
    var c=escape('${content}');
    </script>
    <button type="button" onclick="f_point(t,c);">相关知识点</button>
    <label id="point"/>
    <script type="text/javascript">
    function f_point(title,content)
    {
    document.getElementById("point").innerHTML = unescape(title)+"<br>"+unescape(content);
    }
    </script>