dragonsun00000 2011-06-02 20:33
浏览 121
已采纳

在javascript中传递带有空格的字符串

Hello I have a php code which by echo calls the javascript function expand(txt) with the parameter 'txt'

echo "<div onclick=javascript:expand('$hint1')>$valueX</div>";


function expand(txt)
{

document.getElementById("targetDiv").value=txt;

}

my problem is that this script works only if the '$hint1' is a string without white space, example if $hint="car" everything works but if $hint="red car" the javascript is not working.

Any help would be much appreciated! Thanks!

  • 写回答

3条回答 默认 最新

  • doudongfu8006 2011-06-02 20:40
    关注

    change this line:

    echo "<div onclick=javascript:expand('$hint1')>$valueX</div>";
    

    to this:

    echo "<div onclick=\"expand('$hint1')\">$valueX</div>";
    

    the onclick-event has to be in "" and you don't need the javascript:-label (but the last one shouldn't make a difference, it's just senseless)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料