我有<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/