如何使用JavaScript变量作为jQuery选择器中的参数?
<script type="text/javascript">
$(function(){
$("input").click(function(){
var x = $(this).attr("name");
$("input[id=x]").hide();
});
});
</script>
<input type="text" id="bx"/><input type="button" name="bx"/>
<input type="text" id="by"/><input type="button" name="by"/>
基本上,我想做的就是能够隐藏一个元素,该元素id
等于被单击的元素的名称。
var name = this.name;
$("input[name=" + name + "]").hide();
或者,您可以执行以下操作。
var id = this.id;
$('#' + id).hide();
或者,您也可以发挥作用。
$("#" + this.id).slideUp();
如果要永久删除整个元素,则从页面开始。
$("#" + this.id).remove();
您也可以在此使用它。
$("#" + this.id).slideUp('slow', function (){
$("#" + this.id).remove();
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句