Php HTML中嵌入的JavaScript

Php HTML中嵌入的JavaScript,php,javascript,html,function,drop-down-menu,Php,Javascript,Html,Function,Drop Down Menu,我有一段javascript代码,当进行某个选择时,会在下拉菜单旁边显示一个文本框。在我将它嵌入html之前,它一直工作得很好。我不知道为什么它现在不起作用,尽管它可能真的很琐碎 以下是函数,与现在一样: $public->html .= '<script type="text/javascript">; $(function(){ // initially check the default value in dd_question if($("#dd

我有一段javascript代码,当进行某个选择时,会在下拉菜单旁边显示一个文本框。在我将它嵌入html之前,它一直工作得很好。我不知道为什么它现在不起作用,尽管它可能真的很琐碎

以下是函数,与现在一样:

$public->html .= '<script type="text/javascript">;
    $(function(){
    // initially check the default value in dd_question
    if($("#dd_question").find("option:selected").val() == "0"){
            $("#other_question").show();
          }else{
            $("#other_question").hide();
          }
        $("#dd_question").change(function() {
          if($(this).find("option:selected").val() == "0"){
            $("#other_question").show();
          }else{
            $("#other_question").hide();
          }
        });
    });
  </script>';
这将是伟大的工作再次。有人知道为什么不是吗?

浪费代码

<script type="text/javascript">
$(function() {
  $("#dd_question").change(function() {
    var show = $(this).val() == "0";
    if (show) $("#other_question").show();
    else      $("#other_question").hide();
  }).change();
});
</script>

我不是php用户,但我可以告诉你,这一行的分号可能不应该在那里

$public->html .= '<script type="text/javascript">;

它在哪里不起作用?请尝试将代码缩小到一个小的、相关的部分。阅读整个源代码既困难又耗时-一个更紧凑的示例将为您提供更多答案。它只是不显示任何内容,除了文本框之外,无论选择什么,尽管您尝试过使用调试器吗?$public->html v.s.$page->html是您提供的代码片段中唯一的奇怪之处,这还不足以真正解决问题。另外,对于将文本块分配给变量,您真的应该考虑使用带引号的字符串而不是多行字符串?我的iPhone根本帮不上忙