onclick按钮输入在Chrome中不起作用 [英] onclick button input not working in Chrome

查看:410
本文介绍了onclick按钮输入在Chrome中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 函数doClick()
{
alert(clicked);

$ / code>

HTML代码:

 < div> 
< tr>
< td width =100%>
< tr>
< td>& nbsp;查找:< / td>
< td nowrap>
< input type =textid =Find_Textname =Find_Textsize =7>& nbsp;< input type =checkboxname =Find_ExactMatchvalue =1 检查>
< / td>
< td colspan =2style =cursor:defaultnowrap>完全匹配< / td>
< / tr>
< tr>
< td>& nbsp; In:< / td>
< td>
< select name =Find_DataFile>
< option value =1>第1阶段< / option>
< option value =2>第2阶段< / option>
< / select>
< / td>
< td align =centervalign =top>
< input type =submitvalue =Goonclick =doClick();/>
< / td>
< td align =center>< font class =DataFG> F2< font>< / td>
< / tr>
< / table>
< / td>
< / tr>
< / table>
< / div>

大家好,

上述不会在Chrome(最新版)中触发,但会在IE8和IE10下触发。
我做错了什么?



欣赏任何帮助
感谢

逐步通过我上面提供的代码中的每一行(其中还包括服务器请求以填充名为Find_DataFile的下拉列表,其代码我无法提供)我终于找到导致对象未定义错误的罪魁祸首(因为它的id没有被定义,我调用getElementById将它分配给一个临时对象)。所有工作现在为IE8 IE10 Chrome和Safari。感谢球员们所有的时间和精力来帮助我找到解决方案。非常感谢。现在我可以正常呼吸了!

解决方案

提交按钮是一种特殊类型的按钮,仅用于< form>标签。它运行您在其所属窗体的onsubmit属性中指定的任何函数。请参阅这里了解提交按钮如何与JavaScript交互以及onsubmit形式。如果通过这种方式进行连接,您将能够获得理想的效果。所以要特别注意FORM标记的代码是......

 < body> 
< div>
< form name =myFormaction =http://www.google.comonsubmit =return doClick();方法= POST >
< tr>
< td width =100%>
< tr>
< td>& nbsp;查找:< / td>
< td nowrap>
< input type =textid =Find_Textname =Find_Textsize =7>& nbsp;< input type =checkboxname =Find_ExactMatchvalue =1 检查>
< / td>
< td colspan =2style =cursor:defaultnowrap>完全匹配< / td>
< / tr>
< tr>
< td>& nbsp; In:< / td>
< td>
< select name =Find_DataFile>
< option value =1>第1阶段< / option>
< option value =2>第2阶段< / option>
< / select>
< / td>
< td align =centervalign =top>
< input type =submitvalue =Go/>
< / td>
< td align =center>< font class =DataFG> F2< font>< / td>
< / tr>
< / table>
< / td>
< / tr>
< / table>
< / form>
< / div>
< / body>
< / html>

然后是javascript:

 函数doClick()
{
alert(I've been clicked);
}

这对我很有用:)

Javascript code:

function doClick()
{
  alert("clicked");
}

HTML code:

<div >
<table border="2" cellspacing="0" cellpadding="0" class="TextFG" style="font-family:Arial; font-size:10pt;">
<tr>
<td width="100%">
  <table border="0" style="font-family:Arial; font-size:10pt;" cellspacing="0" cellpadding="3">
    <tr>
      <td>&nbsp;Find:</td>
      <td nowrap>
        <input type="text" id="Find_Text" name="Find_Text" size="7" >&nbsp;<input type="checkbox" name="Find_ExactMatch" value="1" checked>
      </td>
      <td colspan="2" style="cursor:default" nowrap >Exact Match</td>
    </tr>
    <tr>
      <td>&nbsp;In:</td>
      <td>
        <select name="Find_DataFile">
          <option value="1">Stage 1</option>
          <option value="2">Stage 2</option>
        </select>
      </td>
      <td align="center" valign="top">
        <input type="submit" value="Go" onclick="doClick();"/>
      </td>
      <td align="center"><font class="DataFG">F2<font></td>
    </tr>
  </table>
</td>
</tr>
</table>
</div>

Hi all,

Simple code like the above will not fire in Chrome (latest) but will under IE8 and IE10. Am I doing anything wrong ?.

Appreciate any help Thanks

After stepping thru each line in the code I supplied above (which also includes a server request to populate the dropdown named "Find_DataFile" whose code I was not able to supply) I have finally found the culprit that was causing an object not defined error (because it's id was not defined and I was calling getElementById to assign it to an temp object). All working now for IE8 IE10 Chrome and Safari. Thanks guys for all the time and effort to help me find a solution. It is much appreciated. I can breathe normally now lol !

解决方案

The submit button is a special type of button which is ONLY used inside the < form > tags. It runs whatever function you specify in the "onsubmit" attribute of the form it belongs to. Refer Here for an idea of how submit buttons interact with javascript and the form "onsubmit". You will be able to get the desired effect if you wire things up this way. so paying particular attention to the FORM markup the code would be...

<body>
    <div>
        <form name="myForm" action="http://www.google.com" onsubmit="return doClick();" method="post">
            <table border="2" cellspacing="0" cellpadding="0" class="TextFG" style="font-family:Arial; font-size:10pt;">
                <tr>
                    <td width="100%">
                      <table border="0" style="font-family:Arial; font-size:10pt;" cellspacing="0" cellpadding="3">
                        <tr>
                          <td>&nbsp;Find:</td>
                          <td nowrap>
                            <input type="text" id="Find_Text" name="Find_Text" size="7" >&nbsp;<input type="checkbox" name="Find_ExactMatch" value="1" checked>
                          </td>
                          <td colspan="2" style="cursor:default" nowrap >Exact Match</td>
                        </tr>
                        <tr>
                          <td>&nbsp;In:</td>
                          <td>
                            <select name="Find_DataFile">
                              <option value="1">Stage 1</option>
                              <option value="2">Stage 2</option>
                            </select>
                          </td>
                          <td align="center" valign="top">
                            <input type="submit" value="Go" />
                          </td>
                          <td align="center"><font class="DataFG">F2<font></td>
                        </tr>
                      </table>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</body>
</html>

and then the javascript:

function doClick()
{
alert("I've been clicked");
}

And that works for me :)

这篇关于onclick按钮输入在Chrome中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆