使用attr替换html width标签

时间:2018-02-20 11:36:18

标签: javascript node.js nodes attr

我使用以下代码替换

<forms isMvc="1" reg_event_id="" reg_event_batch_id="" form_upload="0" date="2/20/2018" assn_id="30231" frm_embed="0" frm_embed_assnid="">
  <form frm_id="130846" assn_id="30231" login_id="7514230" frm_global_flag="False" frm_sub_assn_flag="False" frm_name="Clubhouse Rental" frm_desc="To request rental of the community clubhouse, click here." frm_instr="Please complete the following fields and then select Submit. Be sure to complete your contact information as we will update you with the status of your request." frm_mgmt_flag="False" frm_roleid="2" frm_submit_text="Your request for rental has been received.  You will hear back from us within 2 business days to confirm your request.  Thank you for using our online service, we hope you found it a useful convenience." frm_template_flag="False" frm_tracking_flag="True" frm_reserve_flag="True" frm_payment_option="" frm_payment_bits="5" post_map_type="" post_url="" post_xml_template="" post_user_name="" post_password="" active_flag="True" create_date="6/6/2017 9:46:08 AM" create_by="D'Marie Jacques" update_date="10/20/2017 11:38:16 AM" update_by="Brenda Mondragon" timestamp="System.Byte[]" frm_file="" email_post_to_assn="False" orig_frm_id="" frm_layout="" lbl_layout="" frm_submit_restrict="0" frm_submit_limit="" frm_start_date="" frm_end_date="" frm_type="Form" req_opt_in="False" opt_in_text="" show_results="False" site_pay_bits="5" type="form" form_admin="1" template_admin="" fld_map_admin="1" logged_in_id="8309584" privs="FA-1, FR-1" frm_preview="0" contact_submit="False" member_submit="False" frm_name_script="Clubhouse Rental" sec_role_seq="10" />
  <field fld_id="1758953" fld_name="instr" fld_name_wrap="0" fld_type="instr" fld_def="Enter Your Name, Address, and How You May Be Reached" fld_req="0" fld_seq="1.000" fld_price="0.0000" fld_enabled="1" fld_status="existing" fld_active="1" fld_ext_price="0.000000" />
  <field fld_id="1758954" fld_name="First Name" fld_name_wrap="0" fld_type="text" fld_def="" fld_req="1" fld_min="-1.00" fld_max="-1.00" fld_tip="" fld_seq="2.000" fld_base="fname" fld_price="0.0000" fld_enabled="1" fld_status="existing" fld_active="1" fld_ext_price="0.000000" />
  <field fld_id="1758955" fld_name="Last Name" fld_name_wrap="0" fld_type="text" fld_def="" fld_req="1" fld_min="-1.00" fld_max="-1.00" fld_tip="" fld_seq="3.000" fld_base="lname" fld_price="0.0000" fld_enabled="1" fld_status="existing" fld_active="1" fld_ext_price="0.000000" />
  <field fld_id="1758956" fld_name="Street Address" fld_name_wrap="0" fld_type="text" fld_req="0" fld_seq="4.000" fld_base="prop_addr1" fld_price="0.0000" fld_enabled="1" fld_status="existing" fld_active="1" fld_ext_price="0.000000" />
  <field fld_id="1758957" fld_name="Day Phone" fld_name_wrap="0" fld_type="text" fld_req="0" fld_seq="5.000" fld_base="com3" fld_price="0.0000" fld_enabled="1" fld_status="existing" fld_active="1" fld_ext_price="0.000000" />
  <field fld_id="1758958" fld_name="Email" fld_name_wrap="0" fld_type="text" fld_req="0" fld_seq="6.000" fld_base="com1" fld_price="0.0000" fld_enabled="1" fld_status="existing" fld_active="1" fld_ext_price="0.000000" />
  <field fld_id="1758959" fld_name="Blank Row" fld_name_wrap="0" fld_type="blankrow" fld_def="10" fld_req="0" fld_seq="7.000" fld_price="0.0000" fld_enabled="1" fld_status="existing" fld_active="1" fld_ext_price="0.000000" />
  <field fld_id="1758960" fld_name="instr" fld_name_wrap="0" fld_type="instr" fld_def="Please Describe the Intended Purpose for the Rental" fld_req="0" fld_seq="8.000" fld_price="0.0000" fld_enabled="1" fld_status="existing" fld_active="1" fld_ext_price="0.000000" />
  <field fld_id="1758961" fld_name="Event Purpose" fld_name_wrap="0" fld_type="textarea" fld_req="0" fld_seq="9.000" fld_price="0.0000" fld_enabled="1" fld_status="existing" fld_active="1" fld_ext_price="0.000000" />
  <field fld_id="1758962" fld_name="Blank Row" fld_name_wrap="0" fld_type="blankrow" fld_def="10" fld_req="0" fld_seq="10.000" fld_price="0.0000" fld_enabled="1" fld_status="existing" fld_active="1" fld_ext_price="0.000000" />
  <field fld_id="1758963" fld_name_wrap="0" fld_type="instr" fld_def="Enter the Date(s) and Time You Would Like to Rent the Clubhouse" fld_req="0" fld_seq="11.000" fld_price="0.0000" fld_enabled="1" fld_status="existing" fld_active="1" fld_ext_price="0.000000" />
  <field fld_id="1758964" fld_name="Deposit" fld_name_wrap="0" fld_type="charge" fld_def="1" fld_req="0" fld_min="-1.00" fld_max="-1.00" fld_tip="" fld_seq="12.000" fld_base="" fld_price="200.0000" fld_enabled="0" fld_status="existing" fld_active="1" fld_ext_price="200.000000" />
  <comms>
    <comm comm_id="8025923" contact_id="8386818" member_id="" comm_num="tkurian@frontsteps.com" comm_type_id="1" create_by="Brenda Mondragon" create_date="1/11/2018 10:46:01 AM" update_by="" update_date="" suspend_date="" primary_flag="True" active="True" publish="1" is_text="False" is_voice="False" add_info="" comm_name="Email" AddTag="comm_num" />
  </comms>
  <vw_contact_info assn_name="ProPayAPI Test Form Pay" member_name="Teddy Kurian" fname="Teddy" lname="Kurian" full_name="Teddy Kurian" contact_id="8386818" prop_addr1="Test" prop_addr2="Test" prop_city_desc="Test" prop_state_code="CO" prop_zip_desc="80000" mail_addr1="Test" mail_addr2="Test" mail_city_desc="Test" mail_state_code="CO" mail_zip_desc="80000" />
  <pay_provider_btn>
    <pay_assn_provider provider="ProPayAPI" provider_acct="27" pay_type_id="1" pay_type="CC" is_acct_pay="1" is_form_pay="1" allow_recurring="0" />
  </pay_provider_btn>
</forms>

输出如下:

$('iframe').map(function(i, el) {
       var amp_iframe = $('<amp-iframe layout="responsive"></amp-iframe>');
       amp_iframe.attr('width', $(this).attr('width'));
       amp_iframe.attr('sandbox', 'allow-scripts allow-same-origin');
return $(this).replaceWith(amp_iframe);
});

我想将<amp-iframe layout=responsive src="https://docs.google.com/forms/d/e/abcxxxxxx/viewform?embedded=true" width=100% height=750 frameborder=0 sandbox="allow-scripts allow-same-origin"></amp-iframe> 转换为width="100%"并删除width="100"。我该怎么做呢?

1 个答案:

答案 0 :(得分:2)

如果您从$clubs = App\Clubs::select('name','city')->get(); 获得"100%",那么您可以使用:

$(this).attr('width')

但请确保通过添加自动防火墙代码获得 $(this).attr('width').replace(/\%/, "") 的价值,否则它会中断。

修改:是的。你可以这样替换:

$(this).attr('width')