javascript - 用 jQuery 替换元素

标签 javascript jquery html

我有<form>我的页面上的 s 我想替换为 <button> s。给我带来困难的是我想使用 <form> 的值将输入作为按钮的 html 提交。

<form action="/postcomment/" method="post">
<inputs>
.
. 
.
<input type="submit" value="Reply">
</form>

成为

<button class="postcomment">Reply</button>

我很难理解这里的链接。我需要获取数据值(例如“Reply”),然后将它们插入到一个 jQuery 操作中的按钮元素中(或者使用 .index() 之类的东西管理排序),但我还没弄清楚如何做到这一点.

最佳答案

此处的工作示例:http://jsfiddle.net/Mch86/

$(document).ready(function(){
    $('form').each(function(){
        button = $('<button>' + $('input[type="submit"]', this).val() + '</button>').addClass($(this).attr('action').replace(/\//g, ''));
        $(this).replaceWith(button);
    });
});

关于javascript - 用 jQuery 替换元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7637803/

相关文章:

javascript - 使用 JavaScript 获取 LDAP 多值字符串属性

javascript - setTimeout 方法 :displaying alerts in two different time intervals

javascript - 从键盘输入时,每 n 个字符后加破折号

javascript - 无法附加 jquery

javascript - 集成自定义 jQuery slider

javascript - HTML/CSS : What is the right way to make sticky menus?

javascript - Mysqli 在 jquery 中返回逗号分隔值不查看该值?

javascript - 获取没有html标签但保留换行符的页面元素文本

javascript - NG 包含范围

javascript - 如何使用 async 或 Promise Node/Express