Javascript a href onclick无法在某些页面上工作

Javascript a href onclick无法在某些页面上工作,javascript,html,forms,onclick,Javascript,Html,Forms,Onclick,我有下面的代码,我在许多页面上使用了类似的代码,但在这个特定页面上,它在ie或ff中都不起作用 代码如下: <form action='/productView.html' method=post name=prod_form> <a href='javascript:;' onclick='document.forms['prod_form'].submit(); return false;' class='button101' style='margin-left:92p

我有下面的代码,我在许多页面上使用了类似的代码,但在这个特定页面上,它在ie或ff中都不起作用

代码如下:

<form action='/productView.html' method=post name=prod_form>
<a  href='javascript:;' onclick='document.forms['prod_form'].submit(); return false;' class='button101' style='margin-left:92px;'>".$button_text."</a>
<input type=hidden name=action value='".$button_text."'>
<input type=hidden name=PRid value=".$databack3[PRid].">
<INPUT type='hidden' name='cat_id' value=".$databack3[prodcatID].">
<INPUT type='hidden' name='for_user_id' value=".$for_user_id.">
<input type=hidden name=source value=".$source."></form>

但是,如果我更改为正常按钮,如下所示,它工作正常:

<form action='/productView.html' method=post name=prod_form>
<input type=submit name=action class=button99 value='".$button_text."' style='margin-left:85px;'
<input type=hidden name=PRid value=".$databack3[PRid].">
<INPUT type='hidden' name='cat_id' value=".$databack3[prodcatID].">
<INPUT type='hidden' name='for_user_id' value=".$for_user_id.">
<input type=hidden name=source value=".$source."></form>


onclick
属性的内容用双引号(“)括起来

需要明确的是,不是属性需要双引号,而是在外部引号中不能有相同类型的引号,除非您转义它们

例如:

  • 好:
  • 好:
  • 好:
  • 好:
  • 确定:
  • 确定:

onclick
属性的内容用双引号(“)括起来

需要明确的是,不是属性需要双引号,而是在外部引号中不能有相同类型的引号,除非您转义它们

例如:

  • 好:
  • 好:
  • 好:
  • 好:
  • 确定:
  • 确定:
    • 这是你的问题

      onclick='document.forms['prod_form'].submit(); return false;'
      
      对HTML参数使用常规引号,您会很好

      由于您似乎正在使用PHP用HTML创建一个字符串,因此您可以尝试这样做以避开引号

      onclick=\"document.forms['prod_form'].submit(); return false;\"
      
      这是你的问题

      onclick='document.forms['prod_form'].submit(); return false;'
      
      对HTML参数使用常规引号,您会很好

      由于您似乎正在使用PHP用HTML创建一个字符串,因此您可以尝试这样做以避开引号

      onclick=\"document.forms['prod_form'].submit(); return false;\"
      

      它无法检测
      表单名称
      ,因为它也在
      单引号中

      <a  href='#' onclick='document.forms["prod_form"].submit(); return false;' 
                 class='button101' style='margin-left:92px;'>".$button_text."</a>
      
      
      

      fiddle:

      它无法检测
      表单名称
      ,因为它也在
      单引号中

      <a  href='#' onclick='document.forms["prod_form"].submit(); return false;' 
                 class='button101' style='margin-left:92px;'>".$button_text."</a>
      
      
      
      小提琴:

      
      希望它能起作用
      
      
      希望它能起作用
      
      这只是因为使用了单引号。 只要换个衣服就行了

      onclick='document.forms['prod_form'].submit(); return false;'
      


      这只是因为使用了单引号。 只要换个衣服就行了

      onclick='document.forms['prod_form'].submit(); return false;'