【问题标题】:innerhtml submit buttoninnerhtml 提交按钮
【发布时间】:2013-01-24 21:47:32
【问题描述】:

我想做什么

我正在使用<form> 研究地址,最终将其显示在 Google 地图上。

在用户进行初始输入后,我将他们引至search.php 页面,其中地址参数被分成它们的组件(即邮政编码、城市),即<input type="text" readonly>。还有一个显示地址的谷歌地图,询问用户显示的地址是否正确。他们可以在YesNo 之间进行选择。

如果地址被判断为不正确,他们点击No 按钮,使各种<input type="text"> 可修改(删除readonly 属性)。

一旦他们单击No,包含提交按钮的<div> 将通过document.getElementById.innerHTML 访问,并且按钮YesNo 将转换为一个新的<input type="submit" value="Look it up"> 按钮。

我的问题!

这个新的Look it up 按钮不能用作提交按钮!!当我点击它时没有任何反应。

请帮忙?

代码:

我的重置功能:

function reset_search() {
  document.getElementById('number').removeAttribute("readonly");
  document.getElementById('street').removeAttribute("readonly");
  document.getElementById('apt').removeAttribute("readonly");
  document.getElementById('postal').removeAttribute("readonly");
  document.getElementById('city').removeAttribute("readonly");

  document.getElementById('lookup').setAttribute('action', './search.php');
  var new_submit = 'Please correct the mistakes above and click on the button below to launch another search<br><input type="submit" name="submit" value="Look it up">';
  document.getElementById('submit_button').innerHTML=new_submit;
}

我的表格:

<form method="post" id="lookup" name="lookup" action="./display.php">
.........
<tr>
    <td valign="top" align="center" colspan="4">
    <div id="submit_button">
    According to the map below, is the address correct?<br>
        <input type="submit" value="Yes" />&nbsp;<input type="button" value="No" onclick="reset_search()" />
    </div>
    </td>
</tr>
</form>

【问题讨论】:

    标签: javascript forms submit innerhtml


    【解决方案1】:

    使用调试器更改后,请仔细查看修改后的源代码。 只要提交按钮在表单内,它就会提交表单。

    http://jsfiddle.net/bighostkim/VC6XJ/

    <form action="foo">
        <input type="submit" onclick="alert(this.form)" />
    </form>
        <input type="submit" onclick="alert(this.form)"/>
    <form action="bar">
        <input type="submit" onclick="alert(this.form)" />
    </form>
    

    正如我在这里进行的实验,将 onclick="alert(this.form)" 添加到您的提交按钮。

    如果显示FormElement,什么都不做,这是w3c标准的大问题。

    如果它显示为 null,并且什么也不做,那么您的提交按钮就在表单之外。

    【讨论】:

    • 谢谢你。确实,它似乎在形式之外。但是,正如您在上面的代码中看到的那样,
      标签位于
      内部,那怎么可能呢?
    • 除非我看到您的代码,否则我无法判断所有可能性。您可能已经包含另一个类似这样的表单 jsfiddle.net/bighostkim/VC6XJ/1,或者您可能在提交按钮之前关闭了表单。
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签