嗨,抱歉,如果我违反了一些规则,而且我的英语水平较低!
我想创建一个允许我复制某些值的函数,例如 Crtl + V !
但是当我尝试警告目标值“未定义”时就知道结果了!
编辑///正确的代码是 CODE :
/*/// Fonction pour copier la valeur d'un champ */
$("i.copy").click(function(){
alert($(this).parent().text());
});
<p>
<label>ID :</label><span>00010023 <i class="bt_action fa fa-clone copy" aria-hidden="true"></i></span>
</p>
我想要的只是点击 i 标签来获取跨度值! 提前致谢,再次抱歉!
最佳答案
使用.text()
而不是.attr("value")
您的范围包含文本而不是值。
$("i.copy").click(function() {
alert($(this).parent().clone() //clone the element
.children() //select all the children
.remove() //remove all the children
.end() //again go back to selected element
.text());
});
演示
$("i.copy").click(function() {
alert($(this).parent().clone() //clone the element
.children() //select all the children
.remove() //remove all the children
.end() //again go back to selected element
.text());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>
<label>ID :</label><span>00010023 <i class="bt_action fa fa-clone copy" aria-hidden="true">trigger</i></span>
</p>
关于javascript - 使用jquery获取div的内容(复制),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48185469/