使用Javascript修改OnClick中的代码

使用Javascript修改OnClick中的代码,javascript,javascript-events,Javascript,Javascript Events,我调用了以前已经创建的onclick。 按钮已经有一个onclick,但是我需要在它进行提交之前再添加一个参数 以下是按钮上的“查看源代码”: <td valign='top' align='right' > <button name="Complete" title="Complete" onClick="document.forms.Maker.action='http://mysite.com:8080/internal/Step.jsp?theId=1903

我调用了以前已经创建的onclick。 按钮已经有一个onclick,但是我需要在它进行提交之前再添加一个参数

以下是按钮上的“查看源代码”:

<td valign='top' align='right' >
  <button name="Complete"  title="Complete"
   onClick="document.forms.Maker.action='http://mysite.com:8080/internal/Step.jsp?theId=19032&target=step20&type=Full';
   document.forms.Maker.submit();return false;">Complete</button>
</td>
这是来自以下代码的警报:

function onclick()
{
document.forms.Maker.action='http://mysite.com:8080/internal/Step.jsp?theId=19032&
target=step20&type=Full';document.forms.Maker.submit();return false;
}
结果应该如下所示:

function onclick()
{
document.forms.Maker.action='http://mysite.com:8080/internal/Step.jsp?theId=19032&
target=step20&type=Full&newParam=true';document.forms.Maker.submit();return false;
}

尝试以下操作:将操作值设置为变量

var oldURI = "http://mysite.com:8080..."
var href = "oldURI" + "&newParam=true"

document.forms.Maker.action='href'
如果此Html是您自己的代码,请执行以下操作:

document.getElementById('Complete').onclick = function()
{
    document.forms.Maker.action=
          'http://mysite.com:8080/internal/Step.jsp?theId=19032&
           target=step20&type=Full&newParam=true';
    document.forms.Maker.submit();
    return false;
}
document.getElementById('Complete').onclick = function()
{
    document.forms.Maker.action=
          'http://mysite.com:8080/internal/Step.jsp?theId=19032&
           target=step20&type=Full&newParam=true';
    document.forms.Maker.submit();
    return false;
}
否则,如果您试图从其他网站更改此事件处理程序,请执行以下操作: 将网站放在名为“myframe”的iframe中,代码如下:

document.getElementById('Complete').onclick = function()
{
    document.forms.Maker.action=
          'http://mysite.com:8080/internal/Step.jsp?theId=19032&
           target=step20&type=Full&newParam=true';
    document.forms.Maker.submit();
    return false;
}
document.getElementById('Complete').onclick = function()
{
    document.forms.Maker.action=
          'http://mysite.com:8080/internal/Step.jsp?theId=19032&
           target=step20&type=Full&newParam=true';
    document.forms.Maker.submit();
    return false;
}
但请记住关闭浏览器的跨域数据源访问限制

例如,在ie中: Internet选项->安全->自定义设置Internet区域->


启用跨域访问数据源

这不是我的代码,它会被渲染,参数中的值可能会更改。所以我需要在最后添加它,不管其他参数有什么。另外,我不控制浏览器,所以不能使用最后一个。这就是我要做的,将操作放入一个变量中。但是onclick对象不允许我将其转换为字符串。