1 回答
TA贡献1921条经验 获得超9个赞
你可以简单地使用innerText
function strip() {
document.querySelector('#pstad-descrptn').value =
document.querySelector('#item-info-container').innerText
};
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="button" id="thebutton" value="strip" onclick="strip();">
<textarea id="pstad-descrptn" name="description" data-val="true" cols="78" rows="20"></textarea>
<div id="item-info-container" class="clipboard copied re-copy" data-clipboard-target="#item-info-container">
<div id="item-pre-description">
<h2 class="h5">Product details:</h2> <div class="product-details__columns"> <p class="product-details__column"> <strong>Item Number:</strong> <span id="product-unique-id">000800209270</span> </p> <p class="product-details__column"> <strong>Brand:</strong> <span>Nikon</span> </p> <p class="product-details__column"> <strong>Model Number:</strong> <span>D3500</span> </p> <p class="product-details__column"> <strong>Colour:</strong> <span>Black</span> </p> <p class="product-details__column"> <strong>Number of Lenses:</strong> <span>2</span> </p> </div> </div>
<div id="item-description">
This Nikon D3500 camera body comes with<br><br>Nikon 18-55mm 1:3.5-5.6G VR Lens<br>Nikon 70-300mm 1:4.5-6.3G ED VR Lens<br>1 battery & charger.<br><br>Shutter count: 426<br><br>The camera and both lens are in perfect working order, and is showing hardly any visible wear (please see photos).<br><br>For more information on this or any other item you may have seen please feel free to send me an email and I will respond as soon as possible.<br><br> </div>
</div>
我希望预先描述是一个没有空格只有换行符的代码块。
然后,您需要分隔段落并将它们组合起来(并消除以第一段结尾的双行)
function strip() {
let item_pre_desc = document.querySelector('#item-pre-description')
let item_desc = document.querySelector('#item-description')
let result = document.querySelector('#pstad-descrptn')
result.value =
item_pre_desc.innerText.replace(/\n+/g,'\n')
+ '\n'
+ item_desc.innerText
};
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="button" id="thebutton" value="strip" onclick="strip();">
<textarea id="pstad-descrptn" name="description" data-val="true" cols="78" rows="20"></textarea>
<div id="item-info-container" class="clipboard copied re-copy" data-clipboard-target="#item-info-container">
<div id="item-pre-description">
<h2 class="h5">Product details:</h2> <div class="product-details__columns"> <p class="product-details__column"> <strong>Item Number:</strong> <span id="product-unique-id">000800209270</span> </p> <p class="product-details__column"> <strong>Brand:</strong> <span>Nikon</span> </p> <p class="product-details__column"> <strong>Model Number:</strong> <span>D3500</span> </p> <p class="product-details__column"> <strong>Colour:</strong> <span>Black</span> </p> <p class="product-details__column"> <strong>Number of Lenses:</strong> <span>2</span> </p> </div> </div>
<div id="item-description">
This Nikon D3500 camera body comes with<br><br>Nikon 18-55mm 1:3.5-5.6G VR Lens<br>Nikon 70-300mm 1:4.5-6.3G ED VR Lens<br>1 battery & charger.<br><br>Shutter count: 426<br><br>The camera and both lens are in perfect working order, and is showing hardly any visible wear (please see photos).<br><br>For more information on this or any other item you may have seen please feel free to send me an email and I will respond as soon as possible.<br><br> </div>
</div>
添加回答
举报