如何将按钮更改为<a> tag

时间:2016-09-14 13:09:04

标签: javascript html

I'm new to javascript and I want to change this with <a> tag

<button type="submit" id='submit_form' name="submit_details" onclick=" $(window).unbind('load');" class="btn btn-primary"> Submit </button>

I have this code to change:

 <a href="#"    style="float:left ;background-color:#26a69a ;color:white ">Submit </a>

7 个答案:

答案 0 :(得分:1)

试试这个

 <a href="#" onclick="document.getElementById('form_id').submit()">Submit</a>

答案 1 :(得分:1)

你不能只使用jQuery的$.replaceWith方法吗?将按钮更改为锚点后,您的活动将毫无用处。您的提交按钮是否应该重定向?

&#13;
&#13;
$(function() {
  $('#submit_form').replaceWith($('<a>', {
    text : 'Submit',
    href : '#',
    css : {
      float: 'left',
      backgroundColor: '#26a69a',
      color: 'white'
    }}));
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button type="submit" id="submit_form"
        name="submit_details" class="btn btn-primary"
        onclick="$(window).unbind('load');">Submit</button>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

试试这个

<input type="button" value="google.com" 
  onClick="javascript:location.href = 'http://google.com';" />

答案 3 :(得分:0)

将您想要的任何ID提供给<a>标记。然后编写此代码并在标记之前添加:

<script>
   function clickButton(){
     javascript:location.href = 'http://google.com';
   }
   document.getElementById("your_id").addEventListener("click",clickButton,false);
</script>

答案 4 :(得分:0)

要保持按钮操作,请通过onclick事件

添加
<a onclick="this.closest('form').submit()" href="#" style="float:left ;background-color:#26a69a ;color:white ">Submit</a>

答案 5 :(得分:0)

你准备做什么?如果您希望<a>标记作为按钮做出反应:

<a href="#" id="myId">my link</a>
<script>
   var link = document.getElementById('myId');
   link.addEventListener('click', function(){
      // rest of the code
   }, false);
</script>

答案 6 :(得分:-2)

试试这个:

<h:panelGroup layout="block" class="col-md-7">
   <span class="submit_form" id="submit_form">
    <a class="submit_form" href="">
    </a>
   </span>
</h:panelGroup>

然后,您可以根据ID或名称在js中为此<a>点击添加所需的href。

尝试这个:

<input id="submit_form" type="submit" name="submit_form" value="SUBMIT" class="submit_form" onclick="document.getElementById('form_id').submit()">