[英]How can I remove HTML elements with JqLite or javascript
how can I remove the following text 'search:' with JqLite or original javascript? 如何使用JqLite或原始javascript删除以下文本“搜索:”?
<label>
search:<input type="text">
<label>
update 更新
I didn't explain the question very clearly. 我没有很清楚地解释这个问题。 All the HTML elements are created by angular directive I can only manipulate DOM with JQLITE or JS maybe.
所有HTML元素都是由angular指令创建的,也许我只能用JQLITE或JS操作DOM。 And also attributes of input may change so I can't replace all the child nodes of label with a new input
而且输入的属性可能会更改,因此我无法用新输入替换label的所有子节点
Please try this 请尝试这个
<html>
<body onload="remove()">
<label>
search:
<input type="text" id="search">
</label>
</body>
<script type="text/javascript">
function remove() {
document.getElementById('search').remove();
}
</script>
</html>
label.innerHtml='<input type="text">'
其中label是该标签标记周围的查询包装
Here's what you need to do.Given that your HTML is like this: 这是您需要做的,因为您的HTML是这样的:
<label>
search:<input type="text">
<label>
You need to first get a hold of the label.You do this with 您首先需要持有该标签。
$("label")
Considering you want to manipulate the text inside, you get $("label").innerHTML.Let's put this in a variable. 考虑到您想在其中操作文本,您将获得$(“ label”)。innerHTML.Let将其放入变量中。
x=$("label").innerHTML;
Then, we use the replace string function to replace the value of "search:" with a blank space. 然后,我们使用replace string函数将“ search:”的值替换为空格。
y=x.replace("search:","");
We finally push back this value of y to the inner HTML by 我们最终通过以下方式将y的值推回内部HTML
$("label").innerHTML=y
You can shorten this into much fewer steps, but I separated them for ease of understanding. 您可以将其缩短为更少的步骤,但是为了便于理解,我将它们分开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.