Javascript 将HTMLString(输入类型为text)解析为字符串。

Javascript 将HTMLString(输入类型为text)解析为字符串。,javascript,jquery,string,Javascript,Jquery,String,我真的需要你的帮助。我有一个带有文本和输入字段的表单 我做了一点jquery,得到了一个大的htmlString: var StringContent = '<p>I am thrilled to share my new listing with you at <input id="additions_info_0_0" name="additions[0][replace][0]" size="21" type="text" value="Property Address

我真的需要你的帮助。我有一个带有文本和输入字段的表单

我做了一点jquery,得到了一个大的htmlString:

var StringContent = '<p>I am thrilled to share my new listing with you at <input id="additions_info_0_0" name="additions[0][replace][0]" size="21" type="text" value="Property Address"><input name="additions[0][find][0]" type="hidden" value="(MUST TYPE Property Address HERE)">. To find out more about this exciting property, or to hear about one of the many others currently on the market, call me to set up an appointment at <input id="additions_info_0_1" name="additions[0][replace][1]" size="17" type="text" value="Phone Number"><input name="additions[0][find][1]" type="hidden" value="(MUST TYPE Phone Number HERE)">. I would be happy to answer your questions, discuss your needs, and set you on track to achieving your real estate goals. Looking forward to hearing from you soon!</p>';
var StringContent='我很高兴能在与您分享我的新列表。要了解更多关于这一令人兴奋的房产的信息,或者了解目前市场上众多其他房产中的一个,请致电我在预约。我很乐意回答你们的问题,讨论你们的需求,让你们走上实现房地产目标的轨道。期待早日收到您的来信

",;
我可以在htmlString中循环并获取输入值,比如输入id=additions\u info\u 0\u 0的“1003 Audelia,Houston,TX 75002”和id additions\u info\u 0\u 1的“469-999-9999”。但我无法将所有字符串和输入值组合成新字符串,就像我很高兴能在德克萨斯州休斯顿奥黛利亚1003号75002与您分享我的新列表一样。要了解更多关于这一令人兴奋的房产的信息,或了解目前市场上众多其他房产中的一个,请致电469-999-9999与我预约。我很乐意回答你们的问题,讨论你们的需求,让你们走上实现房地产目标的轨道。期待早日收到您的来信


我正在尝试解析HTML,但运气不好。任何帮助都将是非常棒的,非常感谢。

您的问题不是很清楚,我希望此代码能够很好地满足您的要求。 以类似的方式更改HTML

<div id="contentDiv">
  <p>I am thrilled to share my new listing with you at
    <input id="additions_info_0_0" name="additions[0][replace][0]" size="21" type="text" value="Property Address">. To find out more about this exciting property, or to hear about one of the many others currently on the market, call me to set up an appointment at
    <input id="additions_info_0_1" name="additions[0][replace][1]" size="17" type="text" value="Phone Number"> I would be happy to answer your questions, discuss your needs, and set you on track to achieving your real estate goals. Looking forward to hearing from you soon!</p>
</div>
<input type="button" id="btnSubmit" value="Submit">

我很高兴能与您在
. 要了解更多关于这一令人兴奋的房产的信息,或者了解市场上其他众多房产中的一个,请致电我,在
我很乐意回答你们的问题,讨论你们的需求,让你们走上实现房地产目标的轨道。期待早日收到您的来信

您的javascript代码如下所示

$('#btnSubmit').on('click', function() {
  alert('test');
  var propertyAdd = $('#additions_info_0_0').val();
  var mobile = $('#additions_info_0_1').val();

  var StringContent = '<p>I am thrilled to share my new listing with you at ' + propertyAdd + '. To find out more about this exciting property, or to hear about one of the many others currently on the market, call me to set up an appointment at ' + mobile + ' I would be happy to answer your questions, discuss your needs, and set you on track to achieving your real estate goals. Looking forward to hearing from you soon!</p>';

  $('#contentDiv').html(StringContent);
});
$('btnSubmit')。在('click',function()上{
警报(“测试”);
var propertyAdd=$('#additions_info_0_0').val();
var mobile=$('#additions_info_0_1').val();
var StringContent='我很高兴能在'+propertyAdd+'与您分享我的新上市信息。要了解更多关于这一令人兴奋的房产的信息,或者了解目前市场上的其他房产,请致电我在'+mobile+'预约。我很乐意回答您的问题,讨论您的需求,并让您踏上实现目标的道路实现您的房地产目标。期待尽快收到您的来信!

'; $('#contentDiv').html(StringContent); });
这段代码将首先显示HTML中的内容,输入值后,您可以单击按钮触发javascript代码,从文本框中获取两个输入值,并重新格式化要显示的文本。然后,您可以根据需要将div中的初始内容更改为格式化内容


在这里,我已经用JQuery完成了这项工作,因为您没有提到您希望代码是什么样子的。

问题是什么?现在还不清楚您想要记录什么,您可以更具体地说明您的需求。