Javascript 用另一个文本替换文本区域中的字符串
我有一个带有表单代码的文本区,用户可以复制并粘贴到他们的网站上 文本区域中的html应该是这样的 更新:请注意,下面的表单包含在文本区域中。这将是文本区域中的纯文本Javascript 用另一个文本替换文本区域中的字符串,javascript,jquery,html,Javascript,Jquery,Html,我有一个带有表单代码的文本区,用户可以复制并粘贴到他们的网站上 文本区域中的html应该是这样的 更新:请注意,下面的表单包含在文本区域中。这将是文本区域中的纯文本 <form action="https://www.xxxxxxx.com/servlet/servlet?encoding=UTF-8" method="POST"> <label for="first_name">First Name</label><input id="first_n
<form action="https://www.xxxxxxx.com/servlet/servlet?encoding=UTF-8" method="POST">
<label for="first_name">First Name</label><input id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>
<label for="last_name">Last Name</label><input id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>
<input type="submit" name="submit">
</form>
名字
姓氏
我想将表单标记的url更改为,并使用jquery或普通javascript将更改后的表单代码复制到另一个文本区域。下面是完整的html
<form>
<textarea rows="10" cols="80" id="oldCode">
<form action="https://www.xxxxxxx.com/servlet/servlet?encoding=UTF-8" method="POST">
<label for="first_name">First Name</label><input id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>
<label for="last_name">Last Name</label><input id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>
<input type="submit" name="submit">
</form>
</textarea>
<button onclick="generateCode()">Generate new Code</button>
<textarea id="newCode" rows="10" cols="80">
</textarea>
</form>
名字
姓氏
生成新代码
将id
添加到您的表单中
说myForm
$('button').click(function(){
var formClone = $('#myForm').clone();
formClone.attr('action', 'https://www.yyyyyyyyy.com/parse.php');
$('#newCode').text(formClone);
)};
将
id
添加到您的表单中
说myForm
$('button').click(function(){
var formClone = $('#myForm').clone();
formClone.attr('action', 'https://www.yyyyyyyyy.com/parse.php');
$('#newCode').text(formClone);
)};
将
id
添加到您的表单中
说myForm
$('button').click(function(){
var formClone = $('#myForm').clone();
formClone.attr('action', 'https://www.yyyyyyyyy.com/parse.php');
$('#newCode').text(formClone);
)};
将
id
添加到您的表单中
说myForm
$('button').click(function(){
var formClone = $('#myForm').clone();
formClone.attr('action', 'https://www.yyyyyyyyy.com/parse.php');
$('#newCode').text(formClone);
)};
为表单提供一个
id
<form action="https://www.xxxxxxx.com/servlet/servlet?encoding=UTF-8" method="POST" id="form">
^
<label for="first_name">First Name</label><input id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>
<label for="last_name">Last Name</label><input id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>
<input type="submit" name="submit">
</form>
为表单提供一个
id
<form action="https://www.xxxxxxx.com/servlet/servlet?encoding=UTF-8" method="POST" id="form">
^
<label for="first_name">First Name</label><input id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>
<label for="last_name">Last Name</label><input id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>
<input type="submit" name="submit">
</form>
为表单提供一个
id
<form action="https://www.xxxxxxx.com/servlet/servlet?encoding=UTF-8" method="POST" id="form">
^
<label for="first_name">First Name</label><input id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>
<label for="last_name">Last Name</label><input id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>
<input type="submit" name="submit">
</form>
为表单提供一个
id
<form action="https://www.xxxxxxx.com/servlet/servlet?encoding=UTF-8" method="POST" id="form">
^
<label for="first_name">First Name</label><input id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>
<label for="last_name">Last Name</label><input id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>
<input type="submit" name="submit">
</form>
您可以按照下面的方式来做,为button元素放置
type=“button”
,因为它每次都提交表单
<button type="button" id="generate" >Generate new Code</button>
生成新代码
在jQuery下面使用,将单击事件绑定到按钮并替换表单的操作属性。注意:-您可以使用相同的代码调用onclick javascript函数,而不是biniding click事件
$(function(){
$("#generate").click(function(){
var value = $('#oldCode').val();
var div = $('<div></div>');
$(div).append(value);
$(div).find('form').attr('action','https://www.yyyyyyyyy.com/parse.php');
$('#newCode').val( $(div).html());
});
});
$(函数(){
$(“#生成”)。单击(函数(){
var值=$('#oldCode').val();
var div=$('');
$(div).追加(值);
$(div).find('form').attr('action','https://www.yyyyyyyyy.com/parse.php');
$('#newCode').val($(div.html());
});
});
您可以通过以下方式完成,为按钮元素放置
type=“button”
,因为它每次都提交表单
<button type="button" id="generate" >Generate new Code</button>
生成新代码
在jQuery下面使用,将单击事件绑定到按钮并替换表单的操作属性。注意:-您可以使用相同的代码调用onclick javascript函数,而不是biniding click事件
$(function(){
$("#generate").click(function(){
var value = $('#oldCode').val();
var div = $('<div></div>');
$(div).append(value);
$(div).find('form').attr('action','https://www.yyyyyyyyy.com/parse.php');
$('#newCode').val( $(div).html());
});
});
$(函数(){
$(“#生成”)。单击(函数(){
var值=$('#oldCode').val();
var div=$('');
$(div).追加(值);
$(div).find('form').attr('action','https://www.yyyyyyyyy.com/parse.php');
$('#newCode').val($(div.html());
});
});
您可以通过以下方式完成,为按钮元素放置
type=“button”
,因为它每次都提交表单
<button type="button" id="generate" >Generate new Code</button>
生成新代码
在jQuery下面使用,将单击事件绑定到按钮并替换表单的操作属性。注意:-您可以使用相同的代码调用onclick javascript函数,而不是biniding click事件
$(function(){
$("#generate").click(function(){
var value = $('#oldCode').val();
var div = $('<div></div>');
$(div).append(value);
$(div).find('form').attr('action','https://www.yyyyyyyyy.com/parse.php');
$('#newCode').val( $(div).html());
});
});
$(函数(){
$(“#生成”)。单击(函数(){
var值=$('#oldCode').val();
var div=$('');
$(div).追加(值);
$(div).find('form').attr('action','https://www.yyyyyyyyy.com/parse.php');
$('#newCode').val($(div.html());
});
});
您可以通过以下方式完成,为按钮元素放置
type=“button”
,因为它每次都提交表单
<button type="button" id="generate" >Generate new Code</button>
生成新代码
在jQuery下面使用,将单击事件绑定到按钮并替换表单的操作属性。注意:-您可以使用相同的代码调用onclick javascript函数,而不是biniding click事件
$(function(){
$("#generate").click(function(){
var value = $('#oldCode').val();
var div = $('<div></div>');
$(div).append(value);
$(div).find('form').attr('action','https://www.yyyyyyyyy.com/parse.php');
$('#newCode').val( $(div).html());
});
});
$(函数(){
$(“#生成”)。单击(函数(){
var值=$('#oldCode').val();
var div=$('');
$(div).追加(值);
$(div).find('form').attr('action','https://www.yyyyyyyyy.com/parse.php');
$('#newCode').val($(div.html());
});
});
这里有一个简单的片段:
$('button').click(function () {
var clone = $($('#oldCode').val()).clone();
clone.attr('action', 'https://www.yyyyyyyyy.com/parse.php');
$('#newCode').val(clone[0].outerHTML);
});
即,只需创建textarea值的克隆,更改属性,并将克隆的HTML添加到其他textarea
.这里有一个简单的片段:
$('button').click(function () {
var clone = $($('#oldCode').val()).clone();
clone.attr('action', 'https://www.yyyyyyyyy.com/parse.php');
$('#newCode').val(clone[0].outerHTML);
});
即,只需创建textarea值的克隆,更改属性,并将克隆的HTML添加到其他textarea
.这里有一个简单的片段:
$('button').click(function () {
var clone = $($('#oldCode').val()).clone();
clone.attr('action', 'https://www.yyyyyyyyy.com/parse.php');
$('#newCode').val(clone[0].outerHTML);
});
即,只需创建textarea值的克隆,更改属性,并将克隆的HTML添加到其他textarea
.这里有一个简单的片段:
$('button').click(function () {
var clone = $($('#oldCode').val()).clone();
clone.attr('action', 'https://www.yyyyyyyyy.com/parse.php');
$('#newCode').val(clone[0].outerHTML);
});
即,只需创建textarea值的克隆,更改属性,并将克隆的HTML添加到其他textarea
.问题中的“表单”是纯文本,而不是HTML元素。问题中的“表单”是纯文本,而不是HTML元素。问题中的“表单”是纯文本,而不是HTML元素。问题中的“表单”是纯文本,而不是HTML元素。表单位于文本区域中。此表单应视为文本该表单位于文本区域中。此表单应视为文本该表单位于文本区域中。此表单应视为文本该表单位于文本区域中。此表格应视为文本