Dar*_*ney 1 html javascript forms onclick
我有以下代码,我在许多页面上使用v类似的代码,但在这个特定的页面上,它只是在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>
Run Code Online (Sandbox Code Playgroud)
但是,如果我更改为正常按钮,如下所示它工作正常:
<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>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
onclick用双引号(")包装属性的内容;
onclick="document.forms['prod_form'].submit(); return false;"
Run Code Online (Sandbox Code Playgroud)
为了清楚起见,并不是属性需要双引号,但你不能在外引号内使用相同类型的引号,除非你逃避它们.
例如:
<a href="#" onclick="do('this');">bar</a><a href="#" onclick='do("this");'>bar</a><a href="#" onclick="do(\"this\");">bar</a><a href="#" onclick='do(\'this\');'>bar</a><a href="#" onclick='do('this');'>bar</a><a href="#" onclick="do("this");">bar</a>