<div class="codetitle"> <span><a style="CURSOR: pointer" data="49146" class="copybut" id="copybut49146" onclick="doCopy('code49146')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code49146"> <br><script> <br><br>function showMessage(msg){ <BR>alert(msg) <BR>} <BR></script> <br><br><form name="formName"> <br><input type="button" value="showMessage" onclick="showMessage('<bean:write name=" beanname property="beanProperty" ignore="true">')"> <br> </form> <br> </div> <br>上述代码当从bean中取出的值是单引号时,加载页面就会报js错。可以使用下面的方法解决。 <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="40860" class="copybut" id="copybut40860" onclick="doCopy('code40860')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code40860"> <br><script> <br><br><br><br><BR></script> <br><form name="formName"> <br><input type="button" value="showMessage" onclick="showMessage()"> <br><input type="hidden" name="msg" value="<bean:write name=" beanname property="beanProperty" ignore="true">" /> <br> </form> <br><br><br><br><br>function showMessage(){ <br>var msg=document.formName.msg.value; <br>alert(msg) <br>}<br> </div>