是否有jQuery函数(或直接javascript)将<span class="emphasis">15.9</span>
转换为15.9
?
基本上我想删除<span>
标记,但保留标记内的内容。
答案 0 :(得分:5)
是的,它被称为unwrap
。您可以在要解开的节点上调用它,因此在您的情况下,我们会在$(".emphasis").contents()
上调用它:
$(".emphasis").contents().unwrap();
示例:
// Show the content of the container prior to unwrapping
console.log("before unwrapping: " + $("#container").html());
// Unwrap
$(".emphasis").contents().unwrap();
// After unwrapping
console.log("after unwrapping: " + $("#container").html());
&#13;
<div id="container">
<span class="emphasis">15.9</span>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
&#13;
跨度中有元素的示例:
// Show the content of the container prior to unwrapping
console.log("before unwrapping: " + $("#container").html());
// Unwrap
$(".emphasis").contents().unwrap();
// After unwrapping
console.log("after unwrapping: " + $("#container").html());
&#13;
<div id="container">
<span class="emphasis"><em>15</em>.9</span>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
&#13;
答案 1 :(得分:2)
尝试
curl -X POST http://api.example.com \
-H "Content-Type:multipart/form-data" \
-F "data={\"key\": \"@text.txt\"};type=application/json"
答案 2 :(得分:0)
JavaScript:
var content = document.getElementByClassName("emphasis").innerHTML;